diff options
author | George Hazan <george.hazan@gmail.com> | 2015-05-10 21:42:17 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2015-05-10 21:42:17 +0000 |
commit | c676c07c3c6bf0867cd3e2e80a89e6b25b2edca9 (patch) | |
tree | c8b67d623e9c8cff7b58413a15c407f3753ee244 /src/modules | |
parent | 850793657b4cea418fbf0daa175a563b43c273b2 (diff) |
- two option pages (Customize/Menus, Contact list/Accounts) -> CDialogBase;
- adaptation of Contact list/Contact names for CDlgBase::NotifyChange;
git-svn-id: http://svn.miranda-ng.org/main/trunk@13519 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/clist/Docking.cpp | 16 | ||||
-rw-r--r-- | src/modules/clist/contacts.cpp | 395 | ||||
-rw-r--r-- | src/modules/clist/genmenu.cpp | 51 | ||||
-rw-r--r-- | src/modules/clist/genmenu.h | 4 | ||||
-rw-r--r-- | src/modules/clist/genmenuopt.cpp | 1185 | ||||
-rw-r--r-- | src/modules/clist/keyboard.cpp | 63 | ||||
-rw-r--r-- | src/modules/clist/protocolorder.cpp | 410 |
7 files changed, 981 insertions, 1143 deletions
diff --git a/src/modules/clist/Docking.cpp b/src/modules/clist/Docking.cpp index 3ebda96ee4..7d9fbd62c6 100644 --- a/src/modules/clist/Docking.cpp +++ b/src/modules/clist/Docking.cpp @@ -109,10 +109,8 @@ static void Docking_AdjustPosition(HWND hwnd, LPRECT rcDisplay, LPRECT rc, bool dockPos = *(LPPOINT)rc;
}
- if (move) {
- MoveWindow(hwnd, rc->left, rc->top, rc->right - rc->left,
- rc->bottom - rc->top, TRUE);
- }
+ if (move)
+ MoveWindow(hwnd, rc->left, rc->top, rc->right - rc->left, rc->bottom - rc->top, TRUE);
}
static void Docking_SetSize(HWND hwnd, LPRECT rc, bool query, bool move)
@@ -319,17 +317,17 @@ int fnDocking_ProcessWindowMessage(WPARAM wParam, LPARAM lParam) POINT pt;
GetClientRect(msg->hwnd, &rc);
if ((docked == DOCKED_LEFT && (short)LOWORD(msg->lParam) > rc.right) ||
- (docked == DOCKED_RIGHT && (short)LOWORD(msg->lParam) < 0)) {
+ (docked == DOCKED_RIGHT && (short)LOWORD(msg->lParam) < 0)) {
ReleaseCapture();
draggingTitle = 0;
docked = 0;
GetCursorPos(&pt);
PostMessage(msg->hwnd, WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(pt.x, pt.y));
SetWindowPos(msg->hwnd, 0, pt.x - rc.right / 2,
- pt.y - GetSystemMetrics(SM_CYFRAME) - GetSystemMetrics(SM_CYSMCAPTION) / 2,
- db_get_dw(NULL, "CList", "Width", 0),
- db_get_dw(NULL, "CList", "Height", 0),
- SWP_NOZORDER);
+ pt.y - GetSystemMetrics(SM_CYFRAME) - GetSystemMetrics(SM_CYSMCAPTION) / 2,
+ db_get_dw(NULL, "CList", "Width", 0),
+ db_get_dw(NULL, "CList", "Height", 0),
+ SWP_NOZORDER);
Docking_Command(msg->hwnd, ABM_REMOVE);
}
return 1;
diff --git a/src/modules/clist/contacts.cpp b/src/modules/clist/contacts.cpp index 711d69dbc5..d370239c84 100644 --- a/src/modules/clist/contacts.cpp +++ b/src/modules/clist/contacts.cpp @@ -95,46 +95,47 @@ static int ProcessDatabaseValueDefault(CONTACTINFO *ci, const char* setting) return 1;
}
-static INT_PTR GetContactInfo(WPARAM, LPARAM lParam) {
+static INT_PTR GetContactInfo(WPARAM, LPARAM lParam)
+{
DBVARIANT dbv;
CONTACTINFO *ci = (CONTACTINFO*)lParam;
-
if (ci == NULL) return 1;
if (ci->szProto == NULL) ci->szProto = (char*)CallService(MS_PROTO_GETCONTACTBASEACCOUNT, (WPARAM)ci->hContact, 0);
if (ci->szProto == NULL) return 1;
+
ci->type = 0;
- switch(ci->dwFlag & 0x7F) {
- case CNF_FIRSTNAME: return ProcessDatabaseValueDefault(ci, "FirstName");
- case CNF_LASTNAME: return ProcessDatabaseValueDefault(ci, "LastName");
- case CNF_NICK: return ProcessDatabaseValueDefault(ci, "Nick");
- case CNF_EMAIL: return ProcessDatabaseValueDefault(ci, "e-mail");
- case CNF_CITY: return ProcessDatabaseValueDefault(ci, "City");
- case CNF_STATE: return ProcessDatabaseValueDefault(ci, "State");
- case CNF_PHONE: return ProcessDatabaseValueDefault(ci, "Phone");
- case CNF_HOMEPAGE: return ProcessDatabaseValueDefault(ci, "Homepage");
- case CNF_ABOUT: return ProcessDatabaseValueDefault(ci, "About");
- case CNF_AGE: return ProcessDatabaseValueDefault(ci, "Age");
- case CNF_GENDER: return ProcessDatabaseValueDefault(ci, "Gender");
- case CNF_FAX: return ProcessDatabaseValueDefault(ci, "Fax");
- case CNF_CELLULAR: return ProcessDatabaseValueDefault(ci, "Cellular");
- case CNF_BIRTHDAY: return ProcessDatabaseValueDefault(ci, "BirthDay");
- case CNF_BIRTHMONTH: return ProcessDatabaseValueDefault(ci, "BirthMonth");
- case CNF_BIRTHYEAR: return ProcessDatabaseValueDefault(ci, "BirthYear");
- case CNF_STREET: return ProcessDatabaseValueDefault(ci, "Street");
- case CNF_ZIP: return ProcessDatabaseValueDefault(ci, "ZIP");
- case CNF_LANGUAGE1: return ProcessDatabaseValueDefault(ci, "Language1");
- case CNF_LANGUAGE2: return ProcessDatabaseValueDefault(ci, "Language2");
- case CNF_LANGUAGE3: return ProcessDatabaseValueDefault(ci, "Language3");
- case CNF_CONAME: return ProcessDatabaseValueDefault(ci, "Company");
- case CNF_CODEPT: return ProcessDatabaseValueDefault(ci, "CompanyDepartment");
- case CNF_COPOSITION: return ProcessDatabaseValueDefault(ci, "CompanyPosition");
- case CNF_COSTREET: return ProcessDatabaseValueDefault(ci, "CompanyStreet");
- case CNF_COCITY: return ProcessDatabaseValueDefault(ci, "CompanyCity");
- case CNF_COSTATE: return ProcessDatabaseValueDefault(ci, "CompanyState");
- case CNF_COZIP: return ProcessDatabaseValueDefault(ci, "CompanyZIP");
- case CNF_COHOMEPAGE: return ProcessDatabaseValueDefault(ci, "CompanyHomepage");
-
- case CNF_CUSTOMNICK:
+ switch (ci->dwFlag & 0x7F) {
+ case CNF_FIRSTNAME: return ProcessDatabaseValueDefault(ci, "FirstName");
+ case CNF_LASTNAME: return ProcessDatabaseValueDefault(ci, "LastName");
+ case CNF_NICK: return ProcessDatabaseValueDefault(ci, "Nick");
+ case CNF_EMAIL: return ProcessDatabaseValueDefault(ci, "e-mail");
+ case CNF_CITY: return ProcessDatabaseValueDefault(ci, "City");
+ case CNF_STATE: return ProcessDatabaseValueDefault(ci, "State");
+ case CNF_PHONE: return ProcessDatabaseValueDefault(ci, "Phone");
+ case CNF_HOMEPAGE: return ProcessDatabaseValueDefault(ci, "Homepage");
+ case CNF_ABOUT: return ProcessDatabaseValueDefault(ci, "About");
+ case CNF_AGE: return ProcessDatabaseValueDefault(ci, "Age");
+ case CNF_GENDER: return ProcessDatabaseValueDefault(ci, "Gender");
+ case CNF_FAX: return ProcessDatabaseValueDefault(ci, "Fax");
+ case CNF_CELLULAR: return ProcessDatabaseValueDefault(ci, "Cellular");
+ case CNF_BIRTHDAY: return ProcessDatabaseValueDefault(ci, "BirthDay");
+ case CNF_BIRTHMONTH: return ProcessDatabaseValueDefault(ci, "BirthMonth");
+ case CNF_BIRTHYEAR: return ProcessDatabaseValueDefault(ci, "BirthYear");
+ case CNF_STREET: return ProcessDatabaseValueDefault(ci, "Street");
+ case CNF_ZIP: return ProcessDatabaseValueDefault(ci, "ZIP");
+ case CNF_LANGUAGE1: return ProcessDatabaseValueDefault(ci, "Language1");
+ case CNF_LANGUAGE2: return ProcessDatabaseValueDefault(ci, "Language2");
+ case CNF_LANGUAGE3: return ProcessDatabaseValueDefault(ci, "Language3");
+ case CNF_CONAME: return ProcessDatabaseValueDefault(ci, "Company");
+ case CNF_CODEPT: return ProcessDatabaseValueDefault(ci, "CompanyDepartment");
+ case CNF_COPOSITION: return ProcessDatabaseValueDefault(ci, "CompanyPosition");
+ case CNF_COSTREET: return ProcessDatabaseValueDefault(ci, "CompanyStreet");
+ case CNF_COCITY: return ProcessDatabaseValueDefault(ci, "CompanyCity");
+ case CNF_COSTATE: return ProcessDatabaseValueDefault(ci, "CompanyState");
+ case CNF_COZIP: return ProcessDatabaseValueDefault(ci, "CompanyZIP");
+ case CNF_COHOMEPAGE: return ProcessDatabaseValueDefault(ci, "CompanyHomepage");
+
+ case CNF_CUSTOMNICK:
{
char* saveProto = ci->szProto; ci->szProto = "CList";
if (ci->hContact != NULL && !ProcessDatabaseValueDefault(ci, "MyHandle")) {
@@ -142,68 +143,69 @@ static INT_PTR GetContactInfo(WPARAM, LPARAM lParam) { return 0;
}
ci->szProto = saveProto;
- break;
}
- case CNF_COUNTRY:
- case CNF_COCOUNTRY:
- if (!GetDatabaseString(ci, (ci->dwFlag & 0x7F) == CNF_COUNTRY ? "CountryName" : "CompanyCountryName", &dbv))
- return 0;
+ break;
- if (!db_get(ci->hContact, ci->szProto, (ci->dwFlag & 0x7F) == CNF_COUNTRY ? "Country" : "CompanyCountry", &dbv)) {
- if (dbv.type == DBVT_WORD) {
- int i, countryCount;
- struct CountryListEntry *countries;
- CallService(MS_UTILS_GETCOUNTRYLIST, (WPARAM)&countryCount, (LPARAM)&countries);
- for (i=0;i<countryCount;i++) {
- if (countries[i].id != dbv.wVal) continue;
+ case CNF_COUNTRY:
+ case CNF_COCOUNTRY:
+ if (!GetDatabaseString(ci, (ci->dwFlag & 0x7F) == CNF_COUNTRY ? "CountryName" : "CompanyCountryName", &dbv))
+ return 0;
- if (ci->dwFlag & CNF_UNICODE) {
- int cbLen = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)countries[i].szName, -1, NULL, 0);
- WCHAR* buf = (WCHAR*)mir_alloc(sizeof(WCHAR)*(cbLen+1));
- if (buf != NULL)
- MultiByteToWideChar(CP_ACP, 0, (LPCSTR)countries[i].szName, -1, buf, cbLen);
- ci->pszVal = (TCHAR*)buf;
- }
- else ci->pszVal = (TCHAR*)mir_strdup(countries[i].szName);
+ if (!db_get(ci->hContact, ci->szProto, (ci->dwFlag & 0x7F) == CNF_COUNTRY ? "Country" : "CompanyCountry", &dbv)) {
+ if (dbv.type == DBVT_WORD) {
+ int i, countryCount;
+ struct CountryListEntry *countries;
+ CallService(MS_UTILS_GETCOUNTRYLIST, (WPARAM)&countryCount, (LPARAM)&countries);
+ for (i = 0; i < countryCount; i++) {
+ if (countries[i].id != dbv.wVal) continue;
- ci->type = CNFT_ASCIIZ;
- db_free(&dbv);
- return 0;
- }
- }
- else return ProcessDatabaseValueDefault(ci, (ci->dwFlag & 0x7F) == CNF_COUNTRY ? "Country" : "CompanyCountry");
- db_free(&dbv);
- }
- break;
-
- case CNF_FIRSTLAST:
- if (!GetDatabaseString(ci, "FirstName", &dbv)) {
- DBVARIANT dbv2;
- if (!GetDatabaseString(ci, "LastName", &dbv2)) {
- ci->type = CNFT_ASCIIZ;
if (ci->dwFlag & CNF_UNICODE) {
- size_t len = wcslen(dbv.pwszVal) + wcslen(dbv2.pwszVal) + 2;
- WCHAR* buf = (WCHAR*)mir_alloc(sizeof(WCHAR)*len);
+ int cbLen = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)countries[i].szName, -1, NULL, 0);
+ WCHAR* buf = (WCHAR*)mir_alloc(sizeof(WCHAR)*(cbLen + 1));
if (buf != NULL)
- wcscat(wcscat(wcscpy(buf, dbv.pwszVal), L" "), dbv2.pwszVal);
- ci->pszVal = (TCHAR*)buf;
- }
- else {
- size_t len = strlen(dbv.pszVal) + strlen(dbv2.pszVal) + 2;
- char* buf = (char*)mir_alloc(len);
- if (buf != NULL)
- strcat(strcat(strcpy(buf, dbv.pszVal), " "), dbv2.pszVal);
+ MultiByteToWideChar(CP_ACP, 0, (LPCSTR)countries[i].szName, -1, buf, cbLen);
ci->pszVal = (TCHAR*)buf;
}
+ else ci->pszVal = (TCHAR*)mir_strdup(countries[i].szName);
+
+ ci->type = CNFT_ASCIIZ;
db_free(&dbv);
- db_free(&dbv2);
return 0;
}
+ }
+ else return ProcessDatabaseValueDefault(ci, (ci->dwFlag & 0x7F) == CNF_COUNTRY ? "Country" : "CompanyCountry");
+ db_free(&dbv);
+ }
+ break;
+
+ case CNF_FIRSTLAST:
+ if (!GetDatabaseString(ci, "FirstName", &dbv)) {
+ DBVARIANT dbv2;
+ if (!GetDatabaseString(ci, "LastName", &dbv2)) {
+ ci->type = CNFT_ASCIIZ;
+ if (ci->dwFlag & CNF_UNICODE) {
+ size_t len = wcslen(dbv.pwszVal) + wcslen(dbv2.pwszVal) + 2;
+ WCHAR* buf = (WCHAR*)mir_alloc(sizeof(WCHAR)*len);
+ if (buf != NULL)
+ wcscat(wcscat(wcscpy(buf, dbv.pwszVal), L" "), dbv2.pwszVal);
+ ci->pszVal = (TCHAR*)buf;
+ }
+ else {
+ size_t len = strlen(dbv.pszVal) + strlen(dbv2.pszVal) + 2;
+ char* buf = (char*)mir_alloc(len);
+ if (buf != NULL)
+ strcat(strcat(strcpy(buf, dbv.pszVal), " "), dbv2.pszVal);
+ ci->pszVal = (TCHAR*)buf;
+ }
db_free(&dbv);
+ db_free(&dbv2);
+ return 0;
}
- break;
+ db_free(&dbv);
+ }
+ break;
- case CNF_UNIQUEID:
+ case CNF_UNIQUEID:
{
if (db_mc_isMeta(ci->hContact)) {
TCHAR buf[40];
@@ -217,10 +219,10 @@ static INT_PTR GetContactInfo(WPARAM, LPARAM lParam) { if ((INT_PTR)uid != CALLSERVICE_NOTFOUND && uid)
if (!ProcessDatabaseValueDefault(ci, uid))
return 0;
-
- break;
}
- case CNF_DISPLAYUID:
+ break;
+
+ case CNF_DISPLAYUID:
{
if (!ProcessDatabaseValueDefault(ci, "display_uid"))
return 0;
@@ -229,123 +231,121 @@ static INT_PTR GetContactInfo(WPARAM, LPARAM lParam) { if (!ProcessDatabaseValueDefault(ci, uid))
return 0;
- break;
}
- case CNF_DISPLAYNC:
- case CNF_DISPLAY:
- {
- int i;
- for (i=0; i < NAMEORDERCOUNT; i++) {
- switch(nameOrder[i]) {
- case 0: // custom name
- {
- // make sure we aren't in CNF_DISPLAYNC mode
- // don't get custom name for NULL contact
- char* saveProto = ci->szProto; ci->szProto = "CList";
- if (ci->hContact != NULL && (ci->dwFlag&0x7F) == CNF_DISPLAY && !ProcessDatabaseValueDefault(ci, "MyHandle")) {
- ci->szProto = saveProto;
- return 0;
- }
+ break;
+
+ case CNF_DISPLAYNC:
+ case CNF_DISPLAY:
+ for (int i = 0; i < NAMEORDERCOUNT; i++) {
+ switch (nameOrder[i]) {
+ case 0: // custom name
+ // make sure we aren't in CNF_DISPLAYNC mode
+ // don't get custom name for NULL contact
+ {
+ char *saveProto = ci->szProto; ci->szProto = "CList";
+ if (ci->hContact != NULL && (ci->dwFlag & 0x7F) == CNF_DISPLAY && !ProcessDatabaseValueDefault(ci, "MyHandle")) {
ci->szProto = saveProto;
- break;
- }
- case 1:
- if (!ProcessDatabaseValueDefault(ci, "Nick")) // nick
- return 0;
- break;
- case 2:
- if (!ProcessDatabaseValueDefault(ci, "FirstName")) // First Name
- return 0;
- break;
- case 3:
- if (!ProcessDatabaseValueDefault(ci, "e-mail")) // E-mail
- return 0;
- break;
- case 4:
- if (!ProcessDatabaseValueDefault(ci, "LastName")) // Last Name
- return 0;
- break;
- case 5: // Unique id
- {
- // protocol must define a PFLAG_UNIQUEIDSETTING
- char *uid = (char*)CallProtoService(ci->szProto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0);
- if ((INT_PTR)uid != CALLSERVICE_NOTFOUND && uid) {
- if (!GetDatabaseString(ci, uid, &dbv)) {
- if (dbv.type == DBVT_BYTE || dbv.type == DBVT_WORD || dbv.type == DBVT_DWORD) {
- long value = (dbv.type == DBVT_BYTE) ? dbv.bVal:(dbv.type == DBVT_WORD ? dbv.wVal : dbv.dVal);
- if (ci->dwFlag & CNF_UNICODE) {
- WCHAR buf[ 40 ];
- _ltow(value, buf, 10);
- ci->pszVal = (TCHAR*)mir_wstrdup(buf);
- }
- else {
- char buf[ 40 ];
- _ltoa(value, buf, 10);
- ci->pszVal = (TCHAR*)mir_strdup(buf);
- }
- ci->type = CNFT_ASCIIZ;
- return 0;
- }
- if (dbv.type == DBVT_ASCIIZ && !(ci->dwFlag & CNF_UNICODE)) {
- ci->type = CNFT_ASCIIZ;
- ci->pszVal = dbv.ptszVal;
- return 0;
- }
- if (dbv.type == DBVT_WCHAR && (ci->dwFlag & CNF_UNICODE)) {
- ci->type = CNFT_ASCIIZ;
- ci->pszVal = dbv.ptszVal;
- return 0;
- }
- }
- }
- break;
+ return 0;
}
- case 6: // first + last name
- case 7: // last + first name
- if (!GetDatabaseString(ci, nameOrder[i] == 6 ? "FirstName" : "LastName", &dbv)) {
- DBVARIANT dbv2;
- if (!GetDatabaseString(ci, nameOrder[i] == 6 ? "LastName" : "FirstName", &dbv2)) {
- ci->type = CNFT_ASCIIZ;
-
+ ci->szProto = saveProto;
+ }
+ break;
+ case 1:
+ if (!ProcessDatabaseValueDefault(ci, "Nick")) // nick
+ return 0;
+ break;
+ case 2:
+ if (!ProcessDatabaseValueDefault(ci, "FirstName")) // First Name
+ return 0;
+ break;
+ case 3:
+ if (!ProcessDatabaseValueDefault(ci, "e-mail")) // E-mail
+ return 0;
+ break;
+ case 4:
+ if (!ProcessDatabaseValueDefault(ci, "LastName")) // Last Name
+ return 0;
+ break;
+ case 5: // Unique id
+ {
+ // protocol must define a PFLAG_UNIQUEIDSETTING
+ char *uid = (char*)CallProtoService(ci->szProto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0);
+ if ((INT_PTR)uid != CALLSERVICE_NOTFOUND && uid) {
+ if (!GetDatabaseString(ci, uid, &dbv)) {
+ if (dbv.type == DBVT_BYTE || dbv.type == DBVT_WORD || dbv.type == DBVT_DWORD) {
+ long value = (dbv.type == DBVT_BYTE) ? dbv.bVal : (dbv.type == DBVT_WORD ? dbv.wVal : dbv.dVal);
if (ci->dwFlag & CNF_UNICODE) {
- size_t len = wcslen(dbv.pwszVal) + wcslen(dbv2.pwszVal) + 2;
- WCHAR* buf = (WCHAR*)mir_alloc(sizeof(WCHAR)*len);
- if (buf != NULL)
- wcscat(wcscat(wcscpy(buf, dbv.pwszVal), L" "), dbv2.pwszVal);
- ci->pszVal = (TCHAR*)buf;
+ WCHAR buf[40];
+ _ltow(value, buf, 10);
+ ci->pszVal = (TCHAR*)mir_wstrdup(buf);
}
else {
- size_t len = strlen(dbv.pszVal) + strlen(dbv2.pszVal) + 2;
- char* buf = (char*)mir_alloc(len);
- if (buf != NULL)
- strcat(strcat(strcpy(buf, dbv.pszVal), " "), dbv2.pszVal);
- ci->pszVal = (TCHAR*)buf;
+ char buf[40];
+ _ltoa(value, buf, 10);
+ ci->pszVal = (TCHAR*)mir_strdup(buf);
}
-
- db_free(&dbv);
- db_free(&dbv2);
+ ci->type = CNFT_ASCIIZ;
+ return 0;
+ }
+ if (dbv.type == DBVT_ASCIIZ && !(ci->dwFlag & CNF_UNICODE)) {
+ ci->type = CNFT_ASCIIZ;
+ ci->pszVal = dbv.ptszVal;
+ return 0;
+ }
+ if (dbv.type == DBVT_WCHAR && (ci->dwFlag & CNF_UNICODE)) {
+ ci->type = CNFT_ASCIIZ;
+ ci->pszVal = dbv.ptszVal;
return 0;
}
- db_free(&dbv);
}
- break;
-
- case 8:
- if (ci->dwFlag & CNF_UNICODE)
- ci->pszVal = (TCHAR*)mir_wstrdup(TranslateW(L"'(Unknown contact)'"));
- else
- ci->pszVal = (TCHAR*)mir_strdup(Translate("'(Unknown contact)'"));
+ }
+ }
+ break;
+ case 6: // first + last name
+ case 7: // last + first name
+ if (!GetDatabaseString(ci, nameOrder[i] == 6 ? "FirstName" : "LastName", &dbv)) {
+ DBVARIANT dbv2;
+ if (!GetDatabaseString(ci, nameOrder[i] == 6 ? "LastName" : "FirstName", &dbv2)) {
ci->type = CNFT_ASCIIZ;
+
+ if (ci->dwFlag & CNF_UNICODE) {
+ size_t len = wcslen(dbv.pwszVal) + wcslen(dbv2.pwszVal) + 2;
+ WCHAR* buf = (WCHAR*)mir_alloc(sizeof(WCHAR)*len);
+ if (buf != NULL)
+ wcscat(wcscat(wcscpy(buf, dbv.pwszVal), L" "), dbv2.pwszVal);
+ ci->pszVal = (TCHAR*)buf;
+ }
+ else {
+ size_t len = strlen(dbv.pszVal) + strlen(dbv2.pszVal) + 2;
+ char* buf = (char*)mir_alloc(len);
+ if (buf != NULL)
+ strcat(strcat(strcpy(buf, dbv.pszVal), " "), dbv2.pszVal);
+ ci->pszVal = (TCHAR*)buf;
+ }
+
+ db_free(&dbv);
+ db_free(&dbv2);
return 0;
}
+ db_free(&dbv);
}
+ break;
+
+ case 8:
+ if (ci->dwFlag & CNF_UNICODE)
+ ci->pszVal = (TCHAR*)mir_wstrdup(TranslateW(L"'(Unknown contact)'"));
+ else
+ ci->pszVal = (TCHAR*)mir_strdup(Translate("'(Unknown contact)'"));
+ ci->type = CNFT_ASCIIZ;
+ return 0;
}
- break;
+ }
+ break;
- case CNF_TIMEZONE: {
+ case CNF_TIMEZONE:
+ {
HANDLE hTz = tmi.createByContact(ci->hContact, 0, TZF_KNOWNONLY);
- if (hTz)
- {
+ if (hTz) {
LPTIME_ZONE_INFORMATION tzi = tmi.getTzi(hTz);
int offset = tzi->Bias + tzi->StandardBias;
@@ -355,22 +355,25 @@ static INT_PTR GetContactInfo(WPARAM, LPARAM lParam) { ci->type = CNFT_ASCIIZ;
return 0;
}
- break;
}
- case CNF_MYNOTES: {
- char* saveProto = ci->szProto; ci->szProto = "UserInfo";
- if (!ProcessDatabaseValueDefault(ci, "MyNotes")) {
- ci->szProto = saveProto;
- return 0;
- }
+ break;
+
+ case CNF_MYNOTES:
+ char* saveProto = ci->szProto; ci->szProto = "UserInfo";
+ if (!ProcessDatabaseValueDefault(ci, "MyNotes")) {
ci->szProto = saveProto;
- break;
+ return 0;
}
+ ci->szProto = saveProto;
+ break;
}
return 1;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+// Options dialog
+
class CContactOptsDlg : public CDlgBase
{
int dragging;
@@ -467,14 +470,14 @@ public: m_nameOrder.HitTest(&hti);
if (hDragItem == hti.hItem)
break;
-
+
TVITEMEX tvi;
tvi.mask = TVIF_HANDLE | TVIF_PARAM;
tvi.hItem = hti.hItem;
m_nameOrder.GetItem(&tvi);
if (tvi.lParam == SIZEOF(nameOrderDescr) - 1)
break;
-
+
if (hti.flags & (TVHT_ONITEM | TVHT_ONITEMRIGHT)) {
TCHAR name[128];
TVINSERTSTRUCT tvis = { 0 };
@@ -488,7 +491,7 @@ public: tvis.hParent = NULL;
tvis.hInsertAfter = hti.hItem;
m_nameOrder.SelectItem(m_nameOrder.InsertItem(&tvis));
- SendMessage(GetParent(m_hwnd), PSM_CHANGED, 0, 0);
+ NotifyChange();
}
}
break;
diff --git a/src/modules/clist/genmenu.cpp b/src/modules/clist/genmenu.cpp index d3a9728510..7270447bcd 100644 --- a/src/modules/clist/genmenu.cpp +++ b/src/modules/clist/genmenu.cpp @@ -69,7 +69,7 @@ void FreeAndNil(void **p) int GetMenuObjbyId(const int id)
{
- for (int i=0; i < g_menus.getCount(); i++)
+ for (int i = 0; i < g_menus.getCount(); i++)
if (g_menus[i]->id == id)
return i;
@@ -131,8 +131,8 @@ int MO_MeasureMenuItem(LPMEASUREITEMSTRUCT mis) if (pimi->iconId == -1)
return FALSE;
- mis->itemWidth = max(0, GetSystemMetrics(SM_CXSMICON)-GetSystemMetrics(SM_CXMENUCHECK)+4);
- mis->itemHeight = GetSystemMetrics(SM_CYSMICON)+2;
+ mis->itemWidth = max(0, GetSystemMetrics(SM_CXSMICON) - GetSystemMetrics(SM_CXMENUCHECK) + 4);
+ mis->itemHeight = GetSystemMetrics(SM_CYSMICON) + 2;
return TRUE;
}
@@ -154,12 +154,12 @@ int MO_DrawMenuItem(LPDRAWITEMSTRUCT dis) if (pimi == NULL || pimi->iconId == -1)
return FALSE;
- int y = (dis->rcItem.bottom - dis->rcItem.top - GetSystemMetrics(SM_CYSMICON))/2+1;
+ int y = (dis->rcItem.bottom - dis->rcItem.top - GetSystemMetrics(SM_CYSMICON)) / 2 + 1;
if (dis->itemState & ODS_SELECTED) {
if (dis->itemState & ODS_CHECKED) {
RECT rc;
- rc.left = 2; rc.right = GetSystemMetrics(SM_CXSMICON)+2;
- rc.top = y; rc.bottom = rc.top+GetSystemMetrics(SM_CYSMICON)+2;
+ rc.left = 2; rc.right = GetSystemMetrics(SM_CXSMICON) + 2;
+ rc.top = y; rc.bottom = rc.top + GetSystemMetrics(SM_CYSMICON) + 2;
FillRect(dis->hDC, &rc, GetSysColorBrush(COLOR_HIGHLIGHT));
ImageList_DrawEx(pimi->parent->m_hMenuIcons, pimi->iconId, dis->hDC, 2, y, 0, 0, CLR_NONE, CLR_DEFAULT, ILD_SELECTED);
}
@@ -168,13 +168,13 @@ int MO_DrawMenuItem(LPDRAWITEMSTRUCT dis) else {
if (dis->itemState & ODS_CHECKED) {
RECT rc;
- rc.left = 0; rc.right = GetSystemMetrics(SM_CXSMICON)+4;
- rc.top = y-2; rc.bottom = rc.top + GetSystemMetrics(SM_CYSMICON)+4;
+ rc.left = 0; rc.right = GetSystemMetrics(SM_CXSMICON) + 4;
+ rc.top = y - 2; rc.bottom = rc.top + GetSystemMetrics(SM_CYSMICON) + 4;
DrawEdge(dis->hDC, &rc, BDR_SUNKENOUTER, BF_RECT);
InflateRect(&rc, -1, -1);
COLORREF menuCol = GetSysColor(COLOR_MENU);
COLORREF hiliteCol = GetSysColor(COLOR_3DHIGHLIGHT);
- HBRUSH hBrush = CreateSolidBrush(RGB((GetRValue(menuCol)+GetRValue(hiliteCol))/2, (GetGValue(menuCol)+GetGValue(hiliteCol))/2, (GetBValue(menuCol)+GetBValue(hiliteCol))/2));
+ HBRUSH hBrush = CreateSolidBrush(RGB((GetRValue(menuCol) + GetRValue(hiliteCol)) / 2, (GetGValue(menuCol) + GetGValue(hiliteCol)) / 2, (GetBValue(menuCol) + GetBValue(hiliteCol)) / 2));
FillRect(dis->hDC, &rc, GetSysColorBrush(COLOR_MENU));
DeleteObject(hBrush);
ImageList_DrawEx(pimi->parent->m_hMenuIcons, pimi->iconId, dis->hDC, 2, y, 0, 0, CLR_NONE, GetSysColor(COLOR_MENU), ILD_BLEND50);
@@ -186,7 +186,7 @@ int MO_DrawMenuItem(LPDRAWITEMSTRUCT dis) int MO_RemoveAllObjects()
{
- for (int i=0; i < g_menus.getCount(); i++)
+ for (int i = 0; i < g_menus.getCount(); i++)
delete g_menus[i];
g_menus.destroy();
return 0;
@@ -379,12 +379,11 @@ PMO_IntMenuItem MO_GetIntMenuItem(HGENMENU wParam) if (result == NULL || wParam == (HGENMENU)0xffff1234 || wParam == HGENMENU_ROOT)
return NULL;
- __try
- {
+ __try {
if (result->signature != MENUITEM_SIGNATURE)
result = NULL;
}
- __except(EXCEPTION_EXECUTE_HANDLER)
+ __except (EXCEPTION_EXECUTE_HANDLER)
{
result = NULL;
}
@@ -426,7 +425,7 @@ INT_PTR MO_ProcessCommandByMenuIdent(WPARAM wParam, LPARAM lParam) PMO_IntMenuItem pimi = NULL;
{
mir_cslock lck(csMenuHook);
- for (int i=0; i < g_menus.getCount(); i++)
+ for (int i = 0; i < g_menus.getCount(); i++)
if ((pimi = MO_RecursiveWalkMenu(g_menus[i]->m_items.first, FindMenuByCommand, (void*)wParam)) != NULL)
break;
}
@@ -578,7 +577,7 @@ struct KillMenuItemsParam KillMenuItemsParam(int _hLangpack) :
hLangpack(_hLangpack),
arItems(10)
- {}
+ {}
int hLangpack;
LIST<TMO_IntMenuItem> arItems;
@@ -599,10 +598,10 @@ void KillModuleMenus(int hLangpack) KillMenuItemsParam param(hLangpack);
mir_cslock lck(csMenuHook);
- for (int i=0; i < g_menus.getCount(); i++)
+ for (int i = 0; i < g_menus.getCount(); i++)
MO_RecursiveWalkMenu(g_menus[i]->m_items.first, (pfnWalkFunc)KillMenuItems, ¶m);
- for (int k=0; k < param.arItems.getCount(); k++)
+ for (int k = 0; k < param.arItems.getCount(); k++)
MO_RemoveMenuItem((WPARAM)param.arItems[k], 0);
}
@@ -620,7 +619,7 @@ static int GetNextObjectMenuItemId() // if menu commands are exausted, pack the menu array
if (NextObjectMenuItemId >= CLISTMENUIDMAX) {
NextObjectMenuItemId = CLISTMENUIDMIN;
- for (int i=0; i < g_menus.getCount(); i++)
+ for (int i = 0; i < g_menus.getCount(); i++)
MO_RecursiveWalkMenu(g_menus[i]->m_items.first, PackMenuItems, NULL);
}
@@ -758,13 +757,13 @@ static int WhereToPlace(HMENU hMenu, PMO_MenuItem mi) {
MENUITEMINFO mii = { sizeof(mii) };
mii.fMask = MIIM_SUBMENU | MIIM_DATA;
- for (int i = GetMenuItemCount(hMenu)-1; i >= 0; i--) {
+ for (int i = GetMenuItemCount(hMenu) - 1; i >= 0; i--) {
GetMenuItemInfo(hMenu, i, TRUE, &mii);
if (mii.fType != MFT_SEPARATOR) {
PMO_IntMenuItem pimi = MO_GetIntMenuItem((HGENMENU)mii.dwItemData);
if (pimi != NULL)
if (pimi->mi.position <= mi->position)
- return i+1;
+ return i + 1;
}
}
@@ -806,7 +805,7 @@ static void InsertMenuItemWithSeparators(HMENU hMenu, int uItem, MENUITEMINFO *l // check for separator before
if (uItem) {
- UINT fType = GetMenuItemTypeData(hMenu, uItem-1, p);
+ UINT fType = GetMenuItemTypeData(hMenu, uItem - 1, p);
if (p != NULL && fType != MFT_SEPARATOR) {
if ((p->mi.position / SEPARATORPOSITIONINTERVAL) != (pimi->mi.position / SEPARATORPOSITIONINTERVAL)) {
// but might be supposed to be after the next one instead
@@ -1038,7 +1037,7 @@ int OnIconLibChanges(WPARAM, LPARAM) {
{
mir_cslock lck(csMenuHook);
- for (int mo=0; mo < g_menus.getCount(); mo++)
+ for (int mo = 0; mo < g_menus.getCount(); mo++)
if ((int)hStatusMenuObject != g_menus[mo]->id) //skip status menu
MO_RecursiveWalkMenu(g_menus[mo]->m_items.first, MO_ReloadIcon, 0);
}
@@ -1074,7 +1073,7 @@ static int MO_RegisterIcon(PMO_IntMenuItem pmi, void*) if ((p = _tcschr(p, '&')) == NULL)
break;
- memmove(p, p+1, sizeof(TCHAR)*(_tcslen(p+1)+1));
+ memmove(p, p + 1, sizeof(TCHAR)*(_tcslen(p + 1) + 1));
if (*p == '\0')
p++;
}
@@ -1102,7 +1101,7 @@ static int MO_RegisterIcon(PMO_IntMenuItem pmi, void*) int RegisterAllIconsInIconLib()
{
// register all icons
- for (int mo=0; mo < g_menus.getCount(); mo++) {
+ for (int mo = 0; mo < g_menus.getCount(); mo++) {
if ((int)hStatusMenuObject == g_menus[mo]->id) //skip status menu
continue;
@@ -1118,7 +1117,7 @@ int TryProcessDoubleClick(MCONTACT hContact) if (iMenuID != -1) {
NotifyEventHooks(hPreBuildContactMenuEvent, hContact, 0);
- PMO_IntMenuItem pimi = (PMO_IntMenuItem)MO_GetDefaultMenuItem((WPARAM)g_menus[ iMenuID ]->m_items.first, 0);
+ PMO_IntMenuItem pimi = (PMO_IntMenuItem)MO_GetDefaultMenuItem((WPARAM)g_menus[iMenuID]->m_items.first, 0);
if (pimi != NULL) {
MO_ProcessCommand(pimi, hContact);
return 0;
@@ -1189,7 +1188,7 @@ int InitGenMenu() bIsGenMenuInited = true;
HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded);
- HookEvent(ME_OPT_INITIALISE, GenMenuOptInit);
+ HookEvent(ME_OPT_INITIALISE, GenMenuOptInit);
return 0;
}
diff --git a/src/modules/clist/genmenu.h b/src/modules/clist/genmenu.h index 6bfa111f93..198d5417bc 100644 --- a/src/modules/clist/genmenu.h +++ b/src/modules/clist/genmenu.h @@ -135,10 +135,12 @@ BOOL FindMenuHanleByGlobalID(HMENU hMenu, int globalID, struct _MenuItemHandles LPTSTR GetMenuItemText(PMO_IntMenuItem);
-int GenMenuOptInit(WPARAM wParam, LPARAM lParam);
+int GenMenuOptInit(WPARAM wParam, LPARAM);
int GetMenuObjbyId(const int id);
int GetMenuItembyId(const int objpos, const int id);
+int ProtocolOrderOptInit(WPARAM wParam, LPARAM);
+
INT_PTR MO_GetMenuItem(WPARAM wParam, LPARAM lParam);
void FreeAndNil(void **p);
#endif
diff --git a/src/modules/clist/genmenuopt.cpp b/src/modules/clist/genmenuopt.cpp index 8bcce682b0..054ac75072 100644 --- a/src/modules/clist/genmenuopt.cpp +++ b/src/modules/clist/genmenuopt.cpp @@ -31,226 +31,134 @@ extern bool bIconsDisabled; extern int DefaultImageListColorDepth; void RebuildProtoMenus(int); -struct OrderData +struct MenuItemOptData : public MZeroedObject { - int dragging; - HTREEITEM hDragItem; - int iInitMenuValue; -}; + ~MenuItemOptData() {} -typedef struct tagMenuItemOptData -{ - TCHAR *name; - TCHAR *defname; - char *uniqname; + int pos; // sort key - int pos; + ptrT name; + ptrT defname; + ptrA uniqname; + bool bShow, bIsSelected; int id; PMO_IntMenuItem pimi; -} - MenuItemOptData, *lpMenuItemOptData; - -static BOOL GetCurrentMenuObjectID(HWND hwndDlg, int* result) -{ - HWND hTree = GetDlgItem(hwndDlg, IDC_MENUOBJECTS); - HTREEITEM hti = TreeView_GetSelection(hTree); - if (hti == NULL) - return FALSE; - - TVITEM tvi; - tvi.mask = TVIF_HANDLE | TVIF_PARAM; - tvi.hItem = hti; - TreeView_GetItem(hTree, &tvi); - *result = (int)tvi.lParam; - return TRUE; -} +}; -static int SaveTree(HWND hwndDlg) +class CGenMenuOptionsPage : public CDlgBase { - int MenuObjectId; - if (!GetCurrentMenuObjectID(hwndDlg, &MenuObjectId)) - return 0; - - HWND hTree = GetDlgItem(hwndDlg, IDC_MENUITEMS); - TCHAR idstr[100]; - - TVITEM tvi; - tvi.hItem = TreeView_GetRoot(hTree); - tvi.cchTextMax = SIZEOF(idstr); - tvi.mask = TVIF_TEXT | TVIF_PARAM | TVIF_HANDLE; - tvi.pszText = idstr; - - int count = 0; - int menupos = GetMenuObjbyId(MenuObjectId); - if (menupos == -1) - return -1; - - TIntMenuObject *pimo = g_menus[menupos]; - - char MenuNameItems[256]; - mir_snprintf(MenuNameItems, SIZEOF(MenuNameItems), "%s_Items", pimo->pszName); - int runtimepos = 100; + int m_bDragging; + int iInitMenuValue; - while (tvi.hItem != NULL) { - TreeView_GetItem(hTree, &tvi); - MenuItemOptData *iod = (MenuItemOptData*)tvi.lParam; - if (iod->pimi) { - char menuItemName[256], DBString[300]; - GetMenuItemName(iod->pimi, menuItemName, sizeof(menuItemName)); + HTREEITEM m_hDragItem; - mir_snprintf(DBString, SIZEOF(DBString), "%s_visible", menuItemName); - db_set_b(NULL, MenuNameItems, DBString, iod->bShow); + void SaveTree() + { + int MenuObjectId; + if (!GetCurrentMenuObjectID(MenuObjectId)) + return; + + TCHAR idstr[100]; + + TVITEMEX tvi; + tvi.hItem = m_menuItems.GetRoot(); + tvi.cchTextMax = SIZEOF(idstr); + tvi.mask = TVIF_TEXT | TVIF_PARAM | TVIF_HANDLE; + tvi.pszText = idstr; + + int count = 0; + int menupos = GetMenuObjbyId(MenuObjectId); + if (menupos == -1) + return; + + TIntMenuObject *pimo = g_menus[menupos]; + + char MenuNameItems[256]; + mir_snprintf(MenuNameItems, SIZEOF(MenuNameItems), "%s_Items", pimo->pszName); + int runtimepos = 100; + + while (tvi.hItem != NULL) { + m_menuItems.GetItem(&tvi); + MenuItemOptData *iod = (MenuItemOptData*)tvi.lParam; + if (iod->pimi) { + char menuItemName[256], DBString[300]; + GetMenuItemName(iod->pimi, menuItemName, sizeof(menuItemName)); + + mir_snprintf(DBString, SIZEOF(DBString), "%s_visible", menuItemName); + db_set_b(NULL, MenuNameItems, DBString, iod->bShow); + + mir_snprintf(DBString, SIZEOF(DBString), "%s_pos", menuItemName); + db_set_dw(NULL, MenuNameItems, DBString, runtimepos); + + mir_snprintf(DBString, SIZEOF(DBString), "%s_name", menuItemName); + if (iod->name != NULL && iod->defname != NULL && + mir_tstrcmp(iod->name, iod->defname) != 0) + db_set_ts(NULL, MenuNameItems, DBString, iod->name); + else + db_unset(NULL, MenuNameItems, DBString); - mir_snprintf(DBString, SIZEOF(DBString), "%s_pos", menuItemName); - db_set_dw(NULL, MenuNameItems, DBString, runtimepos); + runtimepos += 100; + } - mir_snprintf(DBString, SIZEOF(DBString), "%s_name", menuItemName); - if (iod->name != NULL && iod->defname != NULL && - mir_tstrcmp(iod->name, iod->defname) != 0) - db_set_ts(NULL, MenuNameItems, DBString, iod->name); - else - db_unset(NULL, MenuNameItems, DBString); + if (iod->name && !_tcscmp(iod->name, STR_SEPARATOR) && iod->bShow) + runtimepos += SEPARATORPOSITIONINTERVAL; - runtimepos += 100; + tvi.hItem = m_menuItems.GetNextSibling(tvi.hItem); + count++; } - - if (iod->name && !_tcscmp(iod->name, STR_SEPARATOR) && iod->bShow) - runtimepos += SEPARATORPOSITIONINTERVAL; - - tvi.hItem = TreeView_GetNextSibling(hTree, tvi.hItem); - count++; } - return 1; -} -static int BuildMenuObjectsTree(HWND hwndDlg) -{ - TVINSERTSTRUCT tvis; - HWND hTree = GetDlgItem(hwndDlg, IDC_MENUOBJECTS); - int i; - - tvis.hParent = NULL; - tvis.hInsertAfter = TVI_LAST; - tvis.item.mask = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE; - TreeView_DeleteAllItems(hTree); - if (g_menus.getCount() == 0) - return FALSE; - - for (i=0; i < g_menus.getCount(); i++) { - TIntMenuObject *p = g_menus[i]; - if (p->id == (int)hStatusMenuObject || !p->m_bUseUserDefinedItems) - continue; - - tvis.item.lParam = (LPARAM)p->id; - tvis.item.pszText = TranslateTS(p->ptszDisplayName); - tvis.item.iImage = tvis.item.iSelectedImage = TRUE; - TreeView_InsertItem(hTree, &tvis); - } - return 1; -} - -static int sortfunc(const void *a, const void *b) -{ - lpMenuItemOptData *sd1, *sd2; - sd1 = (lpMenuItemOptData *)a; - sd2 = (lpMenuItemOptData *)b; - if ((*sd1)->pos > (*sd2)->pos) - return 1; - - if ((*sd1)->pos < (*sd2)->pos) - return -1; - - return 0; -} - -static int InsertSeparator(HWND hwndDlg) -{ - HWND hMenuTree = GetDlgItem(hwndDlg, IDC_MENUITEMS); - HTREEITEM hti = TreeView_GetSelection(hMenuTree); - if (hti == NULL) - return 1; - - TVITEM tvi = {0}; - tvi.mask = TVIF_HANDLE | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM | TVIF_TEXT; - tvi.hItem = hti; - if (TreeView_GetItem(hMenuTree, &tvi) == FALSE) - return 1; + void FreeTreeData() + { + HTREEITEM hItem = m_menuItems.GetRoot(); + while (hItem != NULL) { + TVITEMEX tvi; + tvi.mask = TVIF_HANDLE | TVIF_PARAM; + tvi.hItem = hItem; + m_menuItems.GetItem(&tvi); + delete (MenuItemOptData *)tvi.lParam; - MenuItemOptData *PD = (MenuItemOptData*)mir_calloc(sizeof(MenuItemOptData)); - PD->id = -1; - PD->name = mir_tstrdup(STR_SEPARATOR); - PD->bShow = true; - PD->pos = ((MenuItemOptData *)tvi.lParam)->pos-1; - - TVINSERTSTRUCT tvis = {0}; - tvis.item.lParam = (LPARAM)(PD); - tvis.item.pszText = PD->name; - tvis.item.iImage = tvis.item.iSelectedImage = PD->bShow; - tvis.hInsertAfter = hti; - tvis.item.mask = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE; - TreeView_InsertItem(hMenuTree, &tvis); - return 1; -} + tvi.lParam = 0; + m_menuItems.SetItem(&tvi); -static void FreeTreeData(HWND hwndDlg) -{ - HTREEITEM hItem = TreeView_GetRoot( GetDlgItem(hwndDlg, IDC_MENUITEMS)); - while (hItem != NULL) { - TVITEM tvi; - tvi.mask = TVIF_HANDLE | TVIF_PARAM; - tvi.hItem = hItem; - TreeView_GetItem( GetDlgItem(hwndDlg, IDC_MENUITEMS), &tvi); - { - MenuItemOptData* O = (MenuItemOptData *)tvi.lParam; - if (O->name) mir_free(O->name); - if (O->defname) mir_free(O->defname); - if (O->uniqname) mir_free(O->uniqname); - mir_free(O); + hItem = m_menuItems.GetNextSibling(hItem); } - - tvi.lParam = 0; - TreeView_SetItem( GetDlgItem(hwndDlg, IDC_MENUITEMS), &tvi); - - hItem = TreeView_GetNextSibling( GetDlgItem(hwndDlg, IDC_MENUITEMS), hItem); } -} -static int BuildTree(HWND hwndDlg, int MenuObjectId, BOOL bReread) -{ - char menuItemName[256], MenuNameItems[256]; - char buf[256]; + void RebuildCurrent() + { + int MenuObjectID; + if (GetCurrentMenuObjectID(MenuObjectID)) + BuildTree(MenuObjectID, true); + } - FreeTreeData(hwndDlg); - TreeView_DeleteAllItems( GetDlgItem(hwndDlg, IDC_MENUITEMS)); + bool BuildTree(int MenuObjectId, bool bReread) + { + char buf[256]; - int menupos = GetMenuObjbyId(MenuObjectId); - if (menupos == -1) - return FALSE; + FreeTreeData(); + m_menuItems.DeleteAllItems(); - TIntMenuObject* pimo = g_menus[menupos]; - if (pimo->m_items.first == NULL) - return FALSE; + int menupos = GetMenuObjbyId(MenuObjectId); + if (menupos == -1) + return false; - mir_snprintf(MenuNameItems, SIZEOF(MenuNameItems), "%s_Items", pimo->pszName); + TIntMenuObject* pimo = g_menus[menupos]; + if (pimo->m_items.first == NULL) + return false; - int count = 0; - { - for (PMO_IntMenuItem p = pimo->m_items.first; p != NULL; p = p->next) - if (p->mi.root == (HGENMENU)-1 || p->mi.root == NULL) - count++; - } + char menuItemName[256], MenuNameItems[256]; + mir_snprintf(MenuNameItems, SIZEOF(MenuNameItems), "%s_Items", pimo->pszName); - lpMenuItemOptData *PDar = (lpMenuItemOptData*)mir_alloc(sizeof(lpMenuItemOptData)*count); + LIST<MenuItemOptData> arItems(20, NumericKeySortT); - count = 0; - { for (PMO_IntMenuItem p = pimo->m_items.first; p != NULL; p = p->next) { if (p->mi.root != (HGENMENU)-1 && p->mi.root != NULL) continue; - MenuItemOptData *PD = (MenuItemOptData*)mir_calloc(sizeof(MenuItemOptData)); + MenuItemOptData *PD = new MenuItemOptData(); GetMenuItemName(p, menuItemName, sizeof(menuItemName)); { DBVARIANT dbv; @@ -280,164 +188,338 @@ static int BuildTree(HWND hwndDlg, int MenuObjectId, BOOL bReread) if (p->UniqName) PD->uniqname = mir_strdup(p->UniqName); - PDar[ count ] = PD; - count++; + arItems.insert(PD); } - } - qsort(PDar, count, sizeof(lpMenuItemOptData), sortfunc); - - SendDlgItemMessage(hwndDlg, IDC_MENUITEMS, WM_SETREDRAW, FALSE, 0); - int lastpos = 0; - bool first = TRUE; - - TVINSERTSTRUCT tvis; - tvis.hParent = NULL; - tvis.hInsertAfter = TVI_LAST; - tvis.item.mask = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE; - for (int i=0; i < count; i++) { - if (PDar[i]->pos - lastpos >= SEPARATORPOSITIONINTERVAL) { - MenuItemOptData *PD = (MenuItemOptData*)mir_calloc(sizeof(MenuItemOptData)); - PD->id = -1; - PD->name = mir_tstrdup(STR_SEPARATOR); - PD->pos = PDar[i]->pos - 1; - PD->bShow = true; - - tvis.item.lParam = (LPARAM)PD; - tvis.item.pszText = PD->name; - tvis.item.iImage = tvis.item.iSelectedImage = PD->bShow; - SendDlgItemMessage(hwndDlg, IDC_MENUITEMS, TVM_INSERTITEM, 0, (LPARAM)&tvis); + m_menuItems.SendMsg(WM_SETREDRAW, FALSE, 0); + int lastpos = 0; + bool bIsFirst = TRUE; + + TVINSERTSTRUCT tvis; + tvis.hParent = NULL; + tvis.hInsertAfter = TVI_LAST; + tvis.item.mask = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE; + for (int i = 0; i < arItems.getCount(); i++) { + auto p = arItems[i]; + if (p->pos - lastpos >= SEPARATORPOSITIONINTERVAL) { + MenuItemOptData *PD = new MenuItemOptData(); + PD->id = -1; + PD->name = mir_tstrdup(STR_SEPARATOR); + PD->pos = p->pos - 1; + PD->bShow = true; + + tvis.item.lParam = (LPARAM)PD; + tvis.item.pszText = PD->name; + tvis.item.iImage = tvis.item.iSelectedImage = PD->bShow; + m_menuItems.InsertItem(&tvis); + } + + tvis.item.lParam = (LPARAM)p; + tvis.item.pszText = p->name; + tvis.item.iImage = tvis.item.iSelectedImage = p->bShow; + + HTREEITEM hti = m_menuItems.InsertItem(&tvis); + if (bIsFirst) { + m_menuItems.SelectItem(hti); + bIsFirst = false; + } + + lastpos = p->pos; } - tvis.item.lParam = (LPARAM)PDar[i]; - tvis.item.pszText = PDar[i]->name; - tvis.item.iImage = tvis.item.iSelectedImage = PDar[i]->bShow; + m_menuItems.SendMsg(WM_SETREDRAW, TRUE, 0); + + ShowWindow(m_warning.GetHwnd(), (pimo->m_bUseUserDefinedItems) ? SW_HIDE : SW_SHOW); + m_menuItems.Enable(pimo->m_bUseUserDefinedItems); + m_btnInsert.Enable(pimo->m_bUseUserDefinedItems); + return 1; + } + + bool GetCurrentMenuObjectID(int &result) + { + HTREEITEM hti = m_menuObjects.GetSelection(); + if (hti == NULL) + return false; + + TVITEMEX tvi; + tvi.mask = TVIF_HANDLE | TVIF_PARAM; + tvi.hItem = hti; + m_menuObjects.GetItem(&tvi); + result = (int)tvi.lParam; + return true; + } - HTREEITEM hti = (HTREEITEM)SendDlgItemMessage(hwndDlg, IDC_MENUITEMS, TVM_INSERTITEM, 0, (LPARAM)&tvis); - if (first) { - TreeView_SelectItem( GetDlgItem(hwndDlg, IDC_MENUITEMS), hti); - first = FALSE; + HTREEITEM MoveItemAbove(HTREEITEM hItem, HTREEITEM hInsertAfter) + { + TVITEMEX tvi = { 0 }; + tvi.mask = TVIF_HANDLE | TVIF_PARAM; + tvi.hItem = hItem; + if (!m_menuItems.GetItem(&tvi)) + return NULL; + + if (hItem && hInsertAfter) { + TCHAR name[128]; + if (hItem == hInsertAfter) + return hItem; + + TVINSERTSTRUCT tvis = { 0 }; + tvis.itemex.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE; + tvis.itemex.stateMask = 0xFFFFFFFF; + tvis.itemex.pszText = name; + tvis.itemex.cchTextMax = SIZEOF(name); + tvis.itemex.hItem = hItem; + tvis.itemex.iImage = tvis.itemex.iSelectedImage = ((MenuItemOptData*)tvi.lParam)->bShow; + if (!m_menuItems.GetItem(&tvis.itemex)) + return NULL; + + m_menuItems.DeleteItem(hItem); + + tvis.hParent = NULL; + tvis.hInsertAfter = hInsertAfter; + return m_menuItems.InsertItem(&tvis); } + return NULL; + } - lastpos = PDar[i]->pos; + CCtrlTreeView m_menuItems, m_menuObjects; + CCtrlCheck m_radio1, m_radio2, m_disableIcons; + CCtrlEdit m_customName, m_service; + CCtrlButton m_btnInsert, m_btnReset, m_btnSet, m_btnDefault; + CCtrlBase m_warning; + +public: + CGenMenuOptionsPage() : + CDlgBase(hInst, IDD_OPT_GENMENU), + m_menuItems(this, IDC_MENUITEMS), + m_menuObjects(this, IDC_MENUOBJECTS), + m_radio1(this, IDC_RADIO1), + m_radio2(this, IDC_RADIO2), + m_disableIcons(this, IDC_DISABLEMENUICONS), + m_btnInsert(this, IDC_INSERTSEPARATOR), + m_btnReset(this, IDC_RESETMENU), + m_btnSet(this, IDC_GENMENU_SET), + m_btnDefault(this, IDC_GENMENU_DEFAULT), + m_customName(this, IDC_GENMENU_CUSTOMNAME), + m_service(this, IDC_GENMENU_SERVICE), + m_warning(this, IDC_NOTSUPPORTWARNING) + { + m_btnSet.OnClick = Callback(this, &CGenMenuOptionsPage::btnSet_Clicked); + m_btnReset.OnClick = Callback(this, &CGenMenuOptionsPage::btnReset_Clicked); + m_btnInsert.OnClick = Callback(this, &CGenMenuOptionsPage::btnInsert_Clicked); + m_btnDefault.OnClick = Callback(this, &CGenMenuOptionsPage::btnDefault_Clicked); + + m_menuObjects.OnSelChanged = Callback(this, &CGenMenuOptionsPage::onMenuObjectChanged); + + m_menuItems.OnSelChanged = Callback(this, &CGenMenuOptionsPage::onMenuItemChanged); + m_menuItems.OnBeginDrag = Callback(this, &CGenMenuOptionsPage::onMenuItemBeginDrag); } - SendDlgItemMessage(hwndDlg, IDC_MENUITEMS, WM_SETREDRAW, TRUE, 0); - mir_free(PDar); - ShowWindow( GetDlgItem(hwndDlg, IDC_NOTSUPPORTWARNING), (pimo->m_bUseUserDefinedItems) ? SW_HIDE : SW_SHOW); - EnableWindow( GetDlgItem(hwndDlg, IDC_MENUITEMS), pimo->m_bUseUserDefinedItems); - EnableWindow( GetDlgItem(hwndDlg, IDC_INSERTSEPARATOR), pimo->m_bUseUserDefinedItems); - return 1; -} + //---- init dialog ------------------------------------------- + virtual void OnInitDialog() + { + iInitMenuValue = db_get_b(NULL, "CList", "MoveProtoMenus", TRUE); -static void RebuildCurrent(HWND hwndDlg) -{ - int MenuObjectID; - if (GetCurrentMenuObjectID(hwndDlg, &MenuObjectID)) - BuildTree(hwndDlg, MenuObjectID, TRUE); -} + HIMAGELIST himlCheckBoxes = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_COLOR32 | ILC_MASK, 2, 2); + ImageList_AddIcon_IconLibLoaded(himlCheckBoxes, SKINICON_OTHER_NOTICK); + ImageList_AddIcon_IconLibLoaded(himlCheckBoxes, SKINICON_OTHER_TICK); -static void ResetMenuItems(HWND hwndDlg) -{ - int MenuObjectID; - if (GetCurrentMenuObjectID(hwndDlg, &MenuObjectID)) - BuildTree(hwndDlg, MenuObjectID, FALSE); -} + m_menuItems.SetImageList(himlCheckBoxes, TVSIL_NORMAL); + m_menuObjects.SetImageList(himlCheckBoxes, TVSIL_NORMAL); -static HTREEITEM MoveItemAbove(HWND hTreeWnd, HTREEITEM hItem, HTREEITEM hInsertAfter) -{ - TVITEM tvi = { 0 }; - tvi.mask = TVIF_HANDLE | TVIF_PARAM; - tvi.hItem = hItem; - if (!SendMessage(hTreeWnd, TVM_GETITEM, 0, (LPARAM)&tvi)) - return NULL; - if (hItem && hInsertAfter) { + if (iInitMenuValue) + m_radio2.SetState(true); + else + m_radio1.SetState(true); + + m_disableIcons.SetState(bIconsDisabled); + + //---- init tree ------------------------------------------- TVINSERTSTRUCT tvis; - TCHAR name[128]; - if (hItem == hInsertAfter) - return hItem; - - tvis.item.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE; - tvis.item.stateMask = 0xFFFFFFFF; - tvis.item.pszText = name; - tvis.item.cchTextMax = SIZEOF(name); - tvis.item.hItem = hItem; - tvis.item.iImage = tvis.item.iSelectedImage = ((MenuItemOptData*)tvi.lParam)->bShow; - if (!SendMessage(hTreeWnd, TVM_GETITEM, 0, (LPARAM)&tvis.item)) - return NULL; - if (!TreeView_DeleteItem(hTreeWnd, hItem)) - return NULL; tvis.hParent = NULL; - tvis.hInsertAfter = hInsertAfter; - return TreeView_InsertItem(hTreeWnd, &tvis); + tvis.hInsertAfter = TVI_LAST; + tvis.item.mask = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE; + + for (int i = 0; i < g_menus.getCount(); i++) { + TIntMenuObject *p = g_menus[i]; + if (p->id == (int)hStatusMenuObject || !p->m_bUseUserDefinedItems) + continue; + + tvis.item.lParam = (LPARAM)p->id; + tvis.item.pszText = TranslateTS(p->ptszDisplayName); + tvis.item.iImage = tvis.item.iSelectedImage = true; + m_menuObjects.InsertItem(&tvis); + } } - return NULL; -} -LRESULT CALLBACK LBTNDOWNProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - if (uMsg == WM_LBUTTONDOWN && !(GetKeyState(VK_CONTROL)&0x8000)) { + virtual void OnApply() + { + bIconsDisabled = m_disableIcons.GetState() != 0; + db_set_b(NULL, "CList", "DisableMenuIcons", bIconsDisabled); + SaveTree(); + + int iNewMenuValue = !m_radio1.GetState(); + if (iNewMenuValue != iInitMenuValue) { + RebuildProtoMenus(iNewMenuValue); + iInitMenuValue = iNewMenuValue; + } + RebuildCurrent(); + } - TVHITTESTINFO hti; - hti.pt.x = (short)LOWORD(lParam); - hti.pt.y = (short)HIWORD(lParam); - // ClientToScreen(hwndDlg, &hti.pt); - // ScreenToClient( GetDlgItem(hwndDlg, IDC_MENUITEMS), &hti.pt); - TreeView_HitTest(hwnd, &hti); - if (hti.flags&TVHT_ONITEMLABEL) { - /// LabelClicked Set/unset selection - TVITEM tvi; - HWND tvw = hwnd; - tvi.mask = TVIF_HANDLE|TVIF_PARAM; - tvi.hItem = hti.hItem; - TreeView_GetItem(tvw, &tvi); - - if (!((MenuItemOptData *)tvi.lParam)->bIsSelected) { /* is not Selected*/ - // reset all selection except current - HTREEITEM hit; - hit = TreeView_GetRoot(tvw); - if (hit) - do { - TVITEM tvi = {0}; - tvi.mask = TVIF_HANDLE|TVIF_PARAM; - tvi.hItem = hit; - TreeView_GetItem(tvw, &tvi); - - if (hti.hItem != hit) - ((MenuItemOptData *)tvi.lParam)->bIsSelected = false; - else - ((MenuItemOptData *)tvi.lParam)->bIsSelected = true; - TreeView_SetItem(tvw, &tvi); - } - while (hit = TreeView_GetNextSibling(tvw, hit)); - } + virtual void OnDestroy() + { + ImageList_Destroy(m_menuItems.GetImageList(TVSIL_NORMAL)); + FreeTreeData(); + } + + void btnInsert_Clicked(CCtrlButton*) + { + HTREEITEM hti = m_menuItems.GetSelection(); + if (hti == NULL) + return; + + TVITEMEX tvi = { 0 }; + tvi.mask = TVIF_HANDLE | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM | TVIF_TEXT; + tvi.hItem = hti; + if (!m_menuItems.GetItem(&tvi)) + return; + + MenuItemOptData *PD = new MenuItemOptData(); + PD->id = -1; + PD->name = mir_tstrdup(STR_SEPARATOR); + PD->bShow = true; + PD->pos = ((MenuItemOptData *)tvi.lParam)->pos - 1; + + TVINSERTSTRUCT tvis = { 0 }; + tvis.item.lParam = (LPARAM)(PD); + tvis.item.pszText = PD->name; + tvis.item.iImage = tvis.item.iSelectedImage = PD->bShow; + tvis.hInsertAfter = hti; + tvis.item.mask = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE; + m_menuItems.InsertItem(&tvis); + + NotifyChange();
+ } + + void btnReset_Clicked(CCtrlButton*) + { + int MenuObjectID; + if (GetCurrentMenuObjectID(MenuObjectID)) { + BuildTree(MenuObjectID, false); + NotifyChange();
} } - return mir_callNextSubclass(hwnd, LBTNDOWNProc, uMsg, wParam, lParam); -} + void btnDefault_Clicked(CCtrlButton*) + { + HTREEITEM hti = m_menuItems.GetSelection(); + if (hti == NULL) + return; -static int handleCustomDraw(HWND hWndTreeView, LPNMTVCUSTOMDRAW pNMTVCD) -{ - if (pNMTVCD == NULL) - return -1; + TVITEMEX tvi; + tvi.mask = TVIF_HANDLE | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM; + tvi.hItem = hti; + m_menuItems.GetItem(&tvi); + + MenuItemOptData *iod = (MenuItemOptData *)tvi.lParam; + if (iod->name && _tcsstr(iod->name, STR_SEPARATOR)) + return; + + iod->name = mir_tstrdup(iod->defname); + + SaveTree(); + RebuildCurrent(); + NotifyChange();
+ } + + void btnSet_Clicked(CCtrlButton*) + { + HTREEITEM hti = m_menuItems.GetSelection(); + if (hti == NULL) + return; + + TVITEMEX tvi; + tvi.mask = TVIF_HANDLE | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM; + tvi.hItem = hti; + m_menuItems.GetItem(&tvi); + + MenuItemOptData *iod = (MenuItemOptData *)tvi.lParam; + if (iod->name && _tcsstr(iod->name, STR_SEPARATOR)) + return; + + iod->name = m_customName.GetText(); + + SaveTree(); + RebuildCurrent(); + NotifyChange();
+ } - switch (pNMTVCD->nmcd.dwDrawStage) { - case CDDS_PREPAINT: - return CDRF_NOTIFYITEMDRAW; + void onMenuObjectChanged(void*) + { + RebuildCurrent(); + } + + void onMenuItemChanged(void*) + { + m_customName.SetTextA(""); + m_service.SetTextA(""); + + m_btnDefault.Enable(false); + m_btnSet.Enable(false); + m_customName.Enable(false); + + HTREEITEM hti = m_menuItems.GetSelection(); + if (hti == NULL) + return; + + TVITEMEX tvi; + tvi.mask = TVIF_HANDLE | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM; + tvi.hItem = hti; + m_menuItems.GetItem(&tvi); + if (tvi.lParam == 0) + return; + + MenuItemOptData *iod = (MenuItemOptData *)tvi.lParam; + if (iod->name && _tcsstr(iod->name, STR_SEPARATOR)) + return; - case CDDS_ITEMPREPAINT: - { + m_customName.SetText(iod->name); + + if (iod->pimi->submenu.first == NULL && iod->uniqname) + m_service.SetTextA(iod->uniqname); + + m_btnDefault.Enable(mir_tstrcmp(iod->name, iod->defname) != 0); + m_btnSet.Enable(true); + m_customName.Enable(true); + } + + void onMenuItemBeginDrag(CCtrlTreeView::TEventInfo *evt) + { + SetCapture(m_hwnd); + m_bDragging = true; + m_hDragItem = evt->nmtv->itemNew.hItem; + m_menuItems.SelectItem(m_hDragItem); + } + + int onMenuItemDraw(LPNMTVCUSTOMDRAW pNMTVCD) + { + if (pNMTVCD == NULL) + return -1; + + switch (pNMTVCD->nmcd.dwDrawStage) { + case CDDS_PREPAINT: + return CDRF_NOTIFYITEMDRAW; + + case CDDS_ITEMPREPAINT: HTREEITEM hItem = (HTREEITEM)pNMTVCD->nmcd.dwItemSpec; TCHAR buf[255]; - TVITEM tvi = { 0 }; + TVITEMEX tvi = { 0 }; tvi.mask = TVIF_HANDLE | TVIF_PARAM | TVIS_SELECTED | TVIF_TEXT | TVIF_IMAGE; tvi.stateMask = TVIS_SELECTED; tvi.hItem = hItem; tvi.pszText = buf; tvi.cchTextMax = SIZEOF(buf); - TreeView_GetItem(hWndTreeView, &tvi); + m_menuItems.GetItem(&tvi); if (((MenuItemOptData *)tvi.lParam)->bIsSelected) { pNMTVCD->clrTextBk = GetSysColor(COLOR_HIGHLIGHT); pNMTVCD->clrText = GetSysColor(COLOR_HIGHLIGHTTEXT); @@ -451,7 +533,7 @@ static int handleCustomDraw(HWND hWndTreeView, LPNMTVCUSTOMDRAW pNMTVCD) and any subitems and return CDRF_NEWFONT. If the list-view control is in report mode, you can simply return CDRF_NOTIFYSUBITEMREDRAW to customize the item's subitems individually */ - int retVal = CDRF_NEWFONT; + int res = CDRF_NEWFONT; if (tvi.iImage == -1) { SIZE sz; GetTextExtentPoint32(pNMTVCD->nmcd.hdc, tvi.pszText, (int)mir_tstrlen(tvi.pszText), &sz); @@ -469,379 +551,190 @@ static int handleCustomDraw(HWND hWndTreeView, LPNMTVCUSTOMDRAW pNMTVCD) DeleteObject(br); DrawText(pNMTVCD->nmcd.hdc, tvi.pszText, -1, &pNMTVCD->nmcd.rc, DT_LEFT | DT_VCENTER | DT_NOPREFIX); - retVal |= CDRF_SKIPDEFAULT; + res |= CDRF_SKIPDEFAULT; } - - return retVal; + return res; } - } - return 0; -} - -static void OnClickCheckbox(HWND hwndDlg, HWND hwndTree, HTREEITEM hItem) -{ - TVITEM tvi; - tvi.mask = TVIF_HANDLE | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM; - tvi.hItem = hItem; - TreeView_GetItem(hwndTree, &tvi); - - tvi.iImage = tvi.iSelectedImage = !tvi.iImage; - ((MenuItemOptData *)tvi.lParam)->bShow = tvi.iImage != 0; - TreeView_SetItem(hwndTree, &tvi); - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); -} -static INT_PTR CALLBACK GenMenuOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - struct OrderData *dat = (struct OrderData*)GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_MENUITEMS), GWLP_USERDATA); - LPNMHDR hdr; - - switch (msg) { - case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); - dat = (struct OrderData*)mir_alloc(sizeof(struct OrderData)); - SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_MENUITEMS), GWLP_USERDATA, (LONG_PTR)dat); - dat->dragging = 0; - dat->iInitMenuValue = db_get_b(NULL, "CList", "MoveProtoMenus", TRUE); - mir_subclassWindow(GetDlgItem(hwndDlg, IDC_MENUITEMS), LBTNDOWNProc); - { - HIMAGELIST himlCheckBoxes; - himlCheckBoxes = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_COLOR32 | ILC_MASK, 2, 2); - - ImageList_AddIcon_IconLibLoaded(himlCheckBoxes, SKINICON_OTHER_NOTICK); - ImageList_AddIcon_IconLibLoaded(himlCheckBoxes, SKINICON_OTHER_TICK); - - TreeView_SetImageList(GetDlgItem(hwndDlg, IDC_MENUOBJECTS), himlCheckBoxes, TVSIL_NORMAL); - TreeView_SetImageList(GetDlgItem(hwndDlg, IDC_MENUITEMS), himlCheckBoxes, TVSIL_NORMAL); - } - CheckDlgButton(hwndDlg, dat->iInitMenuValue ? IDC_RADIO2 : IDC_RADIO1, BST_CHECKED); - CheckDlgButton(hwndDlg, IDC_DISABLEMENUICONS, bIconsDisabled ? BST_CHECKED : BST_UNCHECKED); - BuildMenuObjectsTree(hwndDlg); - return TRUE; - - case WM_COMMAND: - if (HIWORD(wParam) == BN_CLICKED || HIWORD(wParam) == BN_DBLCLK) { - switch (LOWORD(wParam)) { - case IDC_INSERTSEPARATOR: - InsertSeparator(hwndDlg); - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - break; - - case IDC_RESETMENU: - ResetMenuItems(hwndDlg); - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - break; - - case IDC_DISABLEMENUICONS: - case IDC_RADIO1: - case IDC_RADIO2: - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - break; - - case IDC_GENMENU_DEFAULT: - { - HTREEITEM hti = TreeView_GetSelection(GetDlgItem(hwndDlg, IDC_MENUITEMS)); - if (hti == NULL) - break; + return 0; + } - TVITEM tvi; - tvi.mask = TVIF_HANDLE | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM; - tvi.hItem = hti; - TreeView_GetItem(GetDlgItem(hwndDlg, IDC_MENUITEMS), &tvi); - MenuItemOptData *iod = (MenuItemOptData *)tvi.lParam; + void OnClickCheckbox(HTREEITEM hItem) + { + TVITEMEX tvi; + tvi.mask = TVIF_HANDLE | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM; + tvi.hItem = hItem; + m_menuItems.GetItem(&tvi); - if (iod->name && _tcsstr(iod->name, STR_SEPARATOR)) - break; + tvi.iImage = tvi.iSelectedImage = !tvi.iImage; + ((MenuItemOptData *)tvi.lParam)->bShow = tvi.iImage != 0; + m_menuItems.SetItem(&tvi); + + NotifyChange();
+ } - if (iod->name) - mir_free(iod->name); - iod->name = mir_tstrdup(iod->defname); + virtual INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) + { + TVHITTESTINFO hti; - SaveTree(hwndDlg); - RebuildCurrent(hwndDlg); - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - } + switch (msg) { + case WM_MOUSEMOVE: + if (!m_bDragging) break; - case IDC_GENMENU_SET: - { - TCHAR buf[256]; - - HTREEITEM hti = TreeView_GetSelection(GetDlgItem(hwndDlg, IDC_MENUITEMS)); - if (hti == NULL) - break; - - TVITEM tvi; - tvi.mask = TVIF_HANDLE | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM; - tvi.hItem = hti; - SendDlgItemMessage(hwndDlg, IDC_MENUITEMS, TVM_GETITEM, 0, (LPARAM)&tvi); - - MenuItemOptData *iod = (MenuItemOptData *)tvi.lParam; - if (iod->name && _tcsstr(iod->name, STR_SEPARATOR)) - break; - - buf[0] = 0; - GetDlgItemText(hwndDlg, IDC_GENMENU_CUSTOMNAME, buf, SIZEOF(buf)); - if (iod->name) - mir_free(iod->name); - - iod->name = mir_tstrdup(buf); - - SaveTree(hwndDlg); - RebuildCurrent(hwndDlg); - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - } - break; + hti.pt.x = (short)LOWORD(lParam); + hti.pt.y = (short)HIWORD(lParam); + ClientToScreen(m_hwnd, &hti.pt); + ScreenToClient(m_menuItems.GetHwnd(), &hti.pt); + m_menuItems.HitTest(&hti); + if (hti.flags & (TVHT_ONITEM | TVHT_ONITEMRIGHT)) { + HTREEITEM it = hti.hItem; + hti.pt.y -= m_menuItems.GetItemHeight() / 2; + m_menuItems.HitTest(&hti); + if (!(hti.flags & TVHT_ABOVE)) + m_menuItems.SetInsertMark(hti.hItem, 1); + else + m_menuItems.SetInsertMark(it, 0); } - } - break; - - case WM_NOTIFY: - hdr = (LPNMHDR)lParam; - switch (hdr->idFrom) { - case 0: - if (hdr->code == PSN_APPLY) { - bIconsDisabled = IsDlgButtonChecked(hwndDlg, IDC_DISABLEMENUICONS) != 0; - db_set_b(NULL, "CList", "DisableMenuIcons", bIconsDisabled); - SaveTree(hwndDlg); - int iNewMenuValue = IsDlgButtonChecked(hwndDlg, IDC_RADIO1) ? 0 : 1; - if (iNewMenuValue != dat->iInitMenuValue) { - RebuildProtoMenus(iNewMenuValue); - dat->iInitMenuValue = iNewMenuValue; - } - RebuildCurrent(hwndDlg); + else { + if (hti.flags & TVHT_ABOVE) + m_menuItems.SendMsg(WM_VSCROLL, MAKEWPARAM(SB_LINEUP, 0), 0); + if (hti.flags & TVHT_BELOW) + m_menuItems.SendMsg(WM_VSCROLL, MAKEWPARAM(SB_LINEDOWN, 0), 0); + m_menuItems.SetInsertMark(NULL, 0); } break; - case IDC_MENUOBJECTS: - if (hdr->code == TVN_SELCHANGED) - RebuildCurrent(hwndDlg); - break; - - case IDC_MENUITEMS: - switch (hdr->code) { - case NM_CUSTOMDRAW: - SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, handleCustomDraw(GetDlgItem(hwndDlg, IDC_MENUITEMS), (LPNMTVCUSTOMDRAW)lParam)); - return TRUE; - - case TVN_BEGINDRAG: - SetCapture(hwndDlg); - dat->dragging = 1; - dat->hDragItem = ((LPNMTREEVIEW)lParam)->itemNew.hItem; - TreeView_SelectItem(GetDlgItem(hwndDlg, IDC_MENUITEMS), dat->hDragItem); + case WM_LBUTTONUP: + if (!m_bDragging) break; - case TVN_KEYDOWN: - if (((LPNMLVKEYDOWN)lParam)->wVKey == VK_SPACE) - OnClickCheckbox(hwndDlg, hdr->hwndFrom, TreeView_GetSelection(hdr->hwndFrom)); + m_menuItems.SetInsertMark(NULL, 0); + m_bDragging = false; + ReleaseCapture(); + + hti.pt.x = (short)LOWORD(lParam); + hti.pt.y = (short)HIWORD(lParam); + ClientToScreen(m_hwnd, &hti.pt); + ScreenToClient(m_menuItems.GetHwnd(), &hti.pt); + hti.pt.y -= m_menuItems.GetItemHeight() / 2; + m_menuItems.HitTest(&hti); + if (hti.flags & TVHT_ABOVE) + hti.hItem = TVI_FIRST; + if (m_hDragItem == hti.hItem) break; + + m_hDragItem = NULL; + if (hti.flags & (TVHT_ONITEM | TVHT_ONITEMRIGHT) || (hti.hItem == TVI_FIRST)) { + HTREEITEM FirstItem = NULL; + if (m_menuItems.GetCount()) { + LIST<void> arItems(10); - case NM_CLICK: - { - TVHITTESTINFO hti; - hti.pt.x = (short)LOWORD(GetMessagePos()); - hti.pt.y = (short)HIWORD(GetMessagePos()); - ScreenToClient(hdr->hwndFrom, &hti.pt); - if (TreeView_HitTest(hdr->hwndFrom, &hti)) { - if (hti.flags & TVHT_ONITEMICON) - OnClickCheckbox(hwndDlg, hdr->hwndFrom, hti.hItem); - - /*--------MultiSelection----------*/ - if (hti.flags & TVHT_ONITEMLABEL) { - /// LabelClicked Set/unset selection - TVITEM tvi; - HWND tvw = hdr->hwndFrom; + HTREEITEM hit = m_menuItems.GetRoot(); + if (hit) { + do { + TVITEMEX tvi = { 0 }; tvi.mask = TVIF_HANDLE | TVIF_PARAM; - tvi.hItem = hti.hItem; - TreeView_GetItem(tvw, &tvi); - if (GetKeyState(VK_CONTROL) & 0x8000) { - MenuItemOptData *iod = (MenuItemOptData*)tvi.lParam; - iod->bIsSelected = !iod->bIsSelected; - TreeView_SetItem(tvw, &tvi); - } - else if (GetKeyState(VK_SHIFT) & 0x8000) { - ; // shifted click - } - else { - // reset all selection except current - HTREEITEM hit = TreeView_GetRoot(tvw); - if (!hit) - break; - - do { - TVITEM tvi = { 0 }; - tvi.mask = TVIF_HANDLE | TVIF_PARAM; - tvi.hItem = hit; - TreeView_GetItem(tvw, &tvi); - - MenuItemOptData *iod = (MenuItemOptData*)tvi.lParam; - iod->bIsSelected = (hti.hItem == hit); - TreeView_SetItem(tvw, &tvi); - } while (hit = TreeView_GetNextSibling(tvw, hit)); - } - } + tvi.hItem = hit; + m_menuItems.GetItem(&tvi); + if (((MenuItemOptData *)tvi.lParam)->bIsSelected) + arItems.insert(tvi.hItem); + } while (hit = m_menuItems.GetNextSibling(hit)); + } + + // Proceed moving + HTREEITEM insertAfter = hti.hItem; + for (int i = 0; i < arItems.getCount(); i++) { + if (!insertAfter) + break; + + insertAfter = MoveItemAbove((HTREEITEM)arItems[i], insertAfter); + if (!i) + FirstItem = insertAfter; } } - break; - - case TVN_SELCHANGED: - SetDlgItemTextA(hwndDlg, IDC_GENMENU_CUSTOMNAME, ""); - SetDlgItemTextA(hwndDlg, IDC_GENMENU_SERVICE, ""); - - EnableWindow(GetDlgItem(hwndDlg, IDC_GENMENU_CUSTOMNAME), FALSE); - EnableWindow(GetDlgItem(hwndDlg, IDC_GENMENU_DEFAULT), FALSE); - EnableWindow(GetDlgItem(hwndDlg, IDC_GENMENU_SET), FALSE); - - HTREEITEM hti = TreeView_GetSelection(GetDlgItem(hwndDlg, IDC_MENUITEMS)); - if (hti == NULL) - break; - - TVITEM tvi; - tvi.mask = TVIF_HANDLE | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM; - tvi.hItem = hti; - TreeView_GetItem(GetDlgItem(hwndDlg, IDC_MENUITEMS), &tvi); - if (tvi.lParam == 0) - break; - - MenuItemOptData *iod = (MenuItemOptData *)tvi.lParam; - if (iod->name && _tcsstr(iod->name, STR_SEPARATOR)) - break; - - SetDlgItemText(hwndDlg, IDC_GENMENU_CUSTOMNAME, iod->name); - - if (iod->pimi->submenu.first == NULL && iod->uniqname) - SetDlgItemTextA(hwndDlg, IDC_GENMENU_SERVICE, iod->uniqname); - - EnableWindow(GetDlgItem(hwndDlg, IDC_GENMENU_DEFAULT), mir_tstrcmp(iod->name, iod->defname) != 0); - EnableWindow(GetDlgItem(hwndDlg, IDC_GENMENU_SET), TRUE); - EnableWindow(GetDlgItem(hwndDlg, IDC_GENMENU_CUSTOMNAME), TRUE); - break; + if (FirstItem) + m_menuItems.SelectItem(FirstItem); + NotifyChange();
+ SaveTree(); } - } - break; + break; - case WM_MOUSEMOVE: - if (!dat || !dat->dragging) break; - { - TVHITTESTINFO hti; + case WM_NOTIFY: + LPNMHDR phdr = (LPNMHDR)lParam; + if (phdr->idFrom == IDC_MENUITEMS) { + switch (phdr->code) { + case NM_CUSTOMDRAW: + SetWindowLongPtr(m_hwnd, DWLP_MSGRESULT, onMenuItemDraw((LPNMTVCUSTOMDRAW)phdr)); + return TRUE; + + case TVN_KEYDOWN: + if (((LPNMLVKEYDOWN)phdr)->wVKey == VK_SPACE) + OnClickCheckbox(m_menuItems.GetSelection()); + break; - hti.pt.x = (short)LOWORD(lParam); - hti.pt.y = (short)HIWORD(lParam); - ClientToScreen(hwndDlg, &hti.pt); - ScreenToClient(GetDlgItem(hwndDlg, IDC_MENUITEMS), &hti.pt); - TreeView_HitTest(GetDlgItem(hwndDlg, IDC_MENUITEMS), &hti); - if (hti.flags&(TVHT_ONITEM | TVHT_ONITEMRIGHT)) { - HTREEITEM it = hti.hItem; - hti.pt.y -= TreeView_GetItemHeight(GetDlgItem(hwndDlg, IDC_MENUITEMS)) / 2; - TreeView_HitTest(GetDlgItem(hwndDlg, IDC_MENUITEMS), &hti); - if (!(hti.flags&TVHT_ABOVE)) - TreeView_SetInsertMark(GetDlgItem(hwndDlg, IDC_MENUITEMS), hti.hItem, 1); - else - TreeView_SetInsertMark(GetDlgItem(hwndDlg, IDC_MENUITEMS), it, 0); - } - else { - if (hti.flags&TVHT_ABOVE) SendDlgItemMessage(hwndDlg, IDC_MENUITEMS, WM_VSCROLL, MAKEWPARAM(SB_LINEUP, 0), 0); - if (hti.flags&TVHT_BELOW) SendDlgItemMessage(hwndDlg, IDC_MENUITEMS, WM_VSCROLL, MAKEWPARAM(SB_LINEDOWN, 0), 0); - TreeView_SetInsertMark(GetDlgItem(hwndDlg, IDC_MENUITEMS), NULL, 0); - } - } - break; + case NM_CLICK: + TVHITTESTINFO hti; + hti.pt.x = (short)LOWORD(GetMessagePos()); + hti.pt.y = (short)HIWORD(GetMessagePos()); + ScreenToClient(phdr->hwndFrom, &hti.pt); + if (!m_menuItems.HitTest(&hti)) + break; - case WM_LBUTTONUP: - if (!dat->dragging) - break; + if (hti.flags & TVHT_ONITEMICON) + OnClickCheckbox(hti.hItem); + + /*--------MultiSelection----------*/ + if (hti.flags & TVHT_ONITEMLABEL) { + /// LabelClicked Set/unset selection + TVITEMEX tvi; + tvi.mask = TVIF_HANDLE | TVIF_PARAM; + tvi.hItem = hti.hItem; + m_menuItems.GetItem(&tvi); + if (GetKeyState(VK_CONTROL) & 0x8000) { + MenuItemOptData *iod = (MenuItemOptData*)tvi.lParam; + iod->bIsSelected = !iod->bIsSelected; + m_menuItems.SetItem(&tvi); + } + else if (GetKeyState(VK_SHIFT) & 0x8000) { + ; // shifted click + } + else { + // reset all selection except current + HTREEITEM hit = m_menuItems.GetRoot(); + if (!hit) + break; - TreeView_SetInsertMark(GetDlgItem(hwndDlg, IDC_MENUITEMS), NULL, 0); - dat->dragging = 0; - ReleaseCapture(); - { - TVHITTESTINFO hti; - hti.pt.x = (short)LOWORD(lParam); - hti.pt.y = (short)HIWORD(lParam); - ClientToScreen(hwndDlg, &hti.pt); - ScreenToClient(GetDlgItem(hwndDlg, IDC_MENUITEMS), &hti.pt); - hti.pt.y -= TreeView_GetItemHeight(GetDlgItem(hwndDlg, IDC_MENUITEMS)) / 2; - TreeView_HitTest(GetDlgItem(hwndDlg, IDC_MENUITEMS), &hti); - if (hti.flags&TVHT_ABOVE) hti.hItem = TVI_FIRST; - if (dat->hDragItem == hti.hItem) break; - dat->hDragItem = NULL; - if (hti.flags&(TVHT_ONITEM | TVHT_ONITEMRIGHT) || (hti.hItem == TVI_FIRST)) { - HTREEITEM FirstItem = NULL; - HWND tvw = GetDlgItem(hwndDlg, IDC_MENUITEMS); - UINT uITCnt = TreeView_GetCount(tvw); - UINT uSic = 0; - if (uITCnt) { - HTREEITEM *pSIT = (HTREEITEM *)mir_alloc(sizeof(HTREEITEM)*uITCnt); - if (pSIT) { - HTREEITEM hit = TreeView_GetRoot(tvw); - if (hit) { do { - TVITEM tvi = { 0 }; + TVITEMEX tvi = { 0 }; tvi.mask = TVIF_HANDLE | TVIF_PARAM; tvi.hItem = hit; - TreeView_GetItem(tvw, &tvi); - if (((MenuItemOptData *)tvi.lParam)->bIsSelected) { - pSIT[uSic] = tvi.hItem; - uSic++; - } - } while (hit = TreeView_GetNextSibling(tvw, hit)); - } - // Proceed moving - HTREEITEM insertAfter = hti.hItem; - for (UINT i = 0; i < uSic; i++) { - if (insertAfter) insertAfter = MoveItemAbove(tvw, pSIT[i], insertAfter); - else break; - if (!i) FirstItem = insertAfter; + m_menuItems.GetItem(&tvi); + + MenuItemOptData *iod = (MenuItemOptData*)tvi.lParam; + iod->bIsSelected = (hti.hItem == hit); + m_menuItems.SetItem(&tvi); + } while (hit = m_menuItems.GetNextSibling(hit)); } - - // free pointers... - mir_free(pSIT); } } - - if (FirstItem) - TreeView_SelectItem(tvw, FirstItem); - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - SaveTree(hwndDlg); } + break; } - break; - - case WM_DESTROY: - if (dat) - mir_free(dat); - - ImageList_Destroy(TreeView_SetImageList(GetDlgItem(hwndDlg, IDC_MENUOBJECTS), NULL, TVSIL_NORMAL)); - FreeTreeData(hwndDlg); - break; - + return CDlgBase::DlgProc(msg, wParam, lParam); } - return FALSE; -} - -INT_PTR CALLBACK ProtocolOrderOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); +}; int GenMenuOptInit(WPARAM wParam, LPARAM) { OPTIONSDIALOGPAGE odp = { 0 }; - odp.hInstance = hInst; - odp.position = -1000000000; - odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_GENMENU); odp.pszTitle = LPGEN("Menus"); odp.pszGroup = LPGEN("Customize"); - odp.pfnDlgProc = GenMenuOpts; - odp.flags = ODPF_BOLDGROUPS; - Options_AddPage(wParam, &odp); - - odp.position = -10000000; - odp.groupPosition = 1000000; - odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_PROTOCOLORDER); - odp.pszTitle = LPGEN("Accounts"); - odp.pszGroup = LPGEN("Contact list"); - odp.pfnDlgProc = ProtocolOrderOpts; odp.flags = ODPF_BOLDGROUPS; + odp.pDialog = new CGenMenuOptionsPage(); Options_AddPage(wParam, &odp); - return 0; + + return ProtocolOrderOptInit(wParam, 0); } diff --git a/src/modules/clist/keyboard.cpp b/src/modules/clist/keyboard.cpp index 36cd20f270..343d7906ef 100644 --- a/src/modules/clist/keyboard.cpp +++ b/src/modules/clist/keyboard.cpp @@ -31,17 +31,7 @@ static INT_PTR hkHideShow(WPARAM, LPARAM) cli.pfnShowHide(0, 0);
return 0;
}
-/*
-INT_PTR hkSearch(WPARAM wParam, LPARAM lParam)
-{
- DBVARIANT dbv = {0};
- if (!db_get_s(NULL, "CList", "SearchUrl", &dbv)) {
- CallService(MS_UTILS_OPENURL, db_get_b(NULL, "CList", "HKSearchNewWnd", 0), (LPARAM)dbv.pszVal);
- db_free(&dbv);
- }
- return 0;
-}
-*/
+
static INT_PTR hkRead(WPARAM, LPARAM)
{
if (cli.pfnEventsProcessTrayDoubleClick(0) == 0) return TRUE;
@@ -55,26 +45,7 @@ static INT_PTR hkOpts(WPARAM, LPARAM) CallService("Options/OptionsCommand", 0, 0);
return 0;
}
-/*
-static INT_PTR hkCloseMiranda(WPARAM wParam, LPARAM lParam)
-{
- CallService("CloseAction", 0, 0);
- return 0;
-}
-
-INT_PTR hkRestoreStatus(WPARAM wParam, LPARAM lParam)
-{
- int nStatus = db_get_w(NULL, "CList", "Status", ID_STATUS_OFFLINE);
- CallService(MS_CLIST_SETSTATUSMODE, nStatus, 0);
- return 0;
-}
-static INT_PTR hkAllOffline(WPARAM, LPARAM)
-{
- CallService(MS_CLIST_SETSTATUSMODE, ID_STATUS_OFFLINE, 0);
- return 0;
-}
-*/
int InitClistHotKeys(void)
{
CreateServiceFunction("CLIST/HK/SHOWHIDE", hkHideShow);
@@ -96,14 +67,7 @@ int InitClistHotKeys(void) shk.pszService = "CLIST/HK/Read";
shk.DefHotKey = HOTKEYCODE(HOTKEYF_CONTROL|HOTKEYF_SHIFT, 'I');
Hotkey_Register(&shk);
-/*
- shk.pszDescription = "Search in site";
- shk.pszName = "SearchInWeb";
- shk.pszSection = "Main";
- shk.pszService = "CLIST/HK/Search";
- shk.DefHotKey = 846;
- Hotkey_Register(&shk);
-*/
+
shk.ptszDescription = LPGENT("Open Options page");
shk.pszName = "ShowOptions";
shk.ptszSection = _T("Main");
@@ -124,29 +88,6 @@ int InitClistHotKeys(void) shk.pszService = "FindAdd/FindAddCommand";
shk.DefHotKey = HOTKEYCODE(HOTKEYF_CONTROL|HOTKEYF_SHIFT, 'F') | HKF_MIRANDA_LOCAL;
Hotkey_Register(&shk);
-
-/*
- shk.pszDescription = "Close Miranda";
- shk.pszName = "CloseMiranda";
- shk.pszSection = "Main";
- shk.pszService = "CLIST/HK/CloseMiranda";
- shk.DefHotKey = 0;
- Hotkey_Register(&shk);
-
- shk.pszDescription = "Restore last status";
- shk.pszName = "RestoreLastStatus";
- shk.pszSection = "Status";
- shk.pszService = "CLIST/HK/RestoreStatus";
- shk.DefHotKey = 0;
- Hotkey_Register(&shk);
-
- shk.pszDescription = "Set All Offline";
- shk.pszName = "AllOffline";
- shk.pszSection = "Status";
- shk.pszService = "CLIST/HK/AllOffline";
- shk.DefHotKey = 0;
- Hotkey_Register(&shk);
-*/
return 0;
}
diff --git a/src/modules/clist/protocolorder.cpp b/src/modules/clist/protocolorder.cpp index 9a1e02b02b..bab4380b61 100644 --- a/src/modules/clist/protocolorder.cpp +++ b/src/modules/clist/protocolorder.cpp @@ -25,25 +25,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "..\..\core\commonheaders.h"
#include "clc.h"
-typedef struct tagProtocolData
+struct ProtocolData
{
char *RealName;
int show, enabled;
-}
- ProtocolData;
-
-struct ProtocolOrderData
-{
- int dragging;
- HTREEITEM hDragItem;
};
-typedef struct {
- char* protoName;
- int visible;
-}
- tempProtoItem;
-
int isProtoSuitable(PROTO_INTERFACE* ppi)
{
if (ppi == NULL)
@@ -59,14 +46,14 @@ bool CheckProtocolOrder(void) for (;;) {
// Find account with this id
- for (i=0; i < accounts.getCount(); i++)
+ for (i = 0; i < accounts.getCount(); i++)
if (accounts[i]->iOrder == id) break;
// Account with id not found
if (i == accounts.getCount()) {
// Check if this is skipped id, if it is decrement all other ids
bool found = false;
- for (i=0; i < accounts.getCount(); i++) {
+ for (i = 0; i < accounts.getCount(); i++) {
if (accounts[i]->iOrder < 1000000 && accounts[i]->iOrder > id) {
--accounts[i]->iOrder;
found = true;
@@ -80,7 +67,7 @@ bool CheckProtocolOrder(void) if (id < accounts.getCount()) {
// Remove huge ids
- for (i=0; i < accounts.getCount(); i++)
+ for (i = 0; i < accounts.getCount(); i++)
if (accounts[i]->iOrder >= 1000000)
accounts[i]->iOrder = id++;
@@ -89,7 +76,7 @@ bool CheckProtocolOrder(void) if (id < accounts.getCount()) {
// Remove duplicate ids
- for (i=0; i < accounts.getCount(); i++) {
+ for (i = 0; i < accounts.getCount(); i++) {
bool found = false;
for (int j = 0; j < accounts.getCount(); j++) {
if (accounts[j]->iOrder == i) {
@@ -113,233 +100,248 @@ static bool ProtoToInclude(PROTOACCOUNT *pa) return (pd != NULL && pd->type == PROTOTYPE_PROTOCOL);
}
-static int FillTree(HWND hwnd)
+/////////////////////////////////////////////////////////////////////////////////////////
+
+class CProtocolOrderOpts : public CDlgBase
{
- TVINSERTSTRUCT tvis;
- tvis.hParent = NULL;
- tvis.hInsertAfter = TVI_LAST;
- tvis.item.mask = TVIF_PARAM|TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
-
- TreeView_DeleteAllItems(hwnd);
- if (accounts.getCount() == 0)
- return FALSE;
-
- for (int i=0; i < accounts.getCount(); i++) {
- int idx = cli.pfnGetAccountIndexByPos(i);
- if (idx == -1)
- continue;
-
- PROTOACCOUNT *pa = accounts[idx];
- if (!ProtoToInclude(pa))
- continue;
-
- ProtocolData *PD = (ProtocolData*)mir_alloc(sizeof(ProtocolData));
- PD->RealName = pa->szModuleName;
- PD->enabled = Proto_IsAccountEnabled(pa) && isProtoSuitable(pa->ppro);
- PD->show = PD->enabled ? pa->bIsVisible : 100;
-
- tvis.item.lParam = (LPARAM)PD;
- tvis.item.pszText = pa->tszAccountName;
- tvis.item.iImage = tvis.item.iSelectedImage = PD->show;
- TreeView_InsertItem(hwnd, &tvis);
+ void FillTree()
+ {
+ m_order.DeleteAllItems();
+
+ TVINSERTSTRUCT tvis;
+ tvis.hParent = NULL;
+ tvis.hInsertAfter = TVI_LAST;
+ tvis.item.mask = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
+
+ for (int i = 0; i < accounts.getCount(); i++) {
+ int idx = cli.pfnGetAccountIndexByPos(i);
+ if (idx == -1)
+ continue;
+
+ PROTOACCOUNT *pa = accounts[idx];
+ if (!ProtoToInclude(pa))
+ continue;
+
+ ProtocolData *PD = (ProtocolData*)mir_alloc(sizeof(ProtocolData));
+ PD->RealName = pa->szModuleName;
+ PD->enabled = Proto_IsAccountEnabled(pa) && isProtoSuitable(pa->ppro);
+ PD->show = PD->enabled ? pa->bIsVisible : 100;
+
+ tvis.item.lParam = (LPARAM)PD;
+ tvis.item.pszText = pa->tszAccountName;
+ tvis.item.iImage = tvis.item.iSelectedImage = PD->show;
+ m_order.InsertItem(&tvis);
+ }
}
- return 0;
-}
+ bool m_bDragging;
+ HTREEITEM m_hDragItem;
-INT_PTR CALLBACK ProtocolOrderOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- HWND hwndProtoOrder = GetDlgItem(hwndDlg, IDC_PROTOCOLORDER);
- struct ProtocolOrderData *dat = (ProtocolOrderData*)GetWindowLongPtr(hwndProtoOrder, GWLP_USERDATA);
-
- switch (msg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hwndDlg);
- dat = (ProtocolOrderData*)mir_calloc(sizeof(ProtocolOrderData));
- SetWindowLongPtr(hwndProtoOrder, GWLP_USERDATA, (LONG_PTR)dat);
- dat->dragging = 0;
-
- SetWindowLongPtr(hwndProtoOrder, GWL_STYLE, GetWindowLongPtr(hwndProtoOrder, GWL_STYLE) | TVS_NOHSCROLL);
- {
- HIMAGELIST himlCheckBoxes = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_COLOR32|ILC_MASK, 2, 2);
- ImageList_AddIcon_IconLibLoaded(himlCheckBoxes, SKINICON_OTHER_NOTICK);
- ImageList_AddIcon_IconLibLoaded(himlCheckBoxes, SKINICON_OTHER_TICK);
- TreeView_SetImageList(hwndProtoOrder, himlCheckBoxes, TVSIL_NORMAL);
- }
+ CCtrlTreeView m_order;
+ CCtrlButton m_btnReset;
- FillTree(hwndProtoOrder);
- return TRUE;
+public:
+ CProtocolOrderOpts() :
+ CDlgBase(hInst, IDD_OPT_PROTOCOLORDER),
+ m_order(this, IDC_PROTOCOLORDER),
+ m_btnReset(this, IDC_RESETPROTOCOLDATA),
+ m_bDragging(false),
+ m_hDragItem(NULL)
+ {
+ m_btnReset.OnClick = Callback(this, &CProtocolOrderOpts::onReset_Click);
+
+ m_order.OnBeginDrag = Callback(this, &CProtocolOrderOpts::onOrder_BeginDrag);
+ m_order.OnDeleteItem = Callback(this, &CProtocolOrderOpts::onOrder_DeleteItem);
+ }
- case WM_COMMAND:
- if (LOWORD(wParam) == IDC_RESETPROTOCOLDATA && HIWORD(wParam) == BN_CLICKED) {
- for (int i=0; i < accounts.getCount(); i++)
- accounts[i]->iOrder = i;
+ virtual void OnInitDialog()
+ {
+ HIMAGELIST himlCheckBoxes = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_COLOR32 | ILC_MASK, 2, 2);
+ ImageList_AddIcon_IconLibLoaded(himlCheckBoxes, SKINICON_OTHER_NOTICK);
+ ImageList_AddIcon_IconLibLoaded(himlCheckBoxes, SKINICON_OTHER_TICK);
+ m_order.SetImageList(himlCheckBoxes, TVSIL_NORMAL);
- FillTree(hwndProtoOrder);
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, (WPARAM)hwndDlg, 0);
- }
- break;
-
- case WM_NOTIFY:
- switch(((LPNMHDR)lParam)->idFrom) {
- case 0:
- if (((LPNMHDR)lParam)->code == PSN_APPLY) {
- int idx = 0;
-
- TVITEM tvi;
- tvi.hItem = TreeView_GetRoot(hwndProtoOrder);
- tvi.cchTextMax = 32;
- tvi.mask = TVIF_PARAM | TVIF_HANDLE;
-
- while (tvi.hItem != NULL) {
- TreeView_GetItem(hwndProtoOrder, &tvi);
-
- if (tvi.lParam != 0) {
- ProtocolData* ppd = (ProtocolData*)tvi.lParam;
- PROTOACCOUNT *pa = Proto_GetAccount(ppd->RealName);
- if (pa != NULL) {
- while (idx < accounts.getCount() && !ProtoToInclude(accounts[idx])) idx++;
- pa->iOrder = idx++;
- if (ppd->enabled)
- pa->bIsVisible = ppd->show != 0;
- }
- }
+ FillTree();
+ }
- tvi.hItem = TreeView_GetNextSibling(hwndProtoOrder, tvi.hItem);
+ virtual void OnApply()
+ {
+ int idx = 0;
+
+ TVITEMEX tvi;
+ tvi.hItem = m_order.GetRoot();
+ tvi.mask = TVIF_PARAM | TVIF_HANDLE;
+ while (tvi.hItem != NULL) {
+ m_order.GetItem(&tvi);
+
+ if (tvi.lParam != 0) {
+ ProtocolData *ppd = (ProtocolData*)tvi.lParam;
+ PROTOACCOUNT *pa = Proto_GetAccount(ppd->RealName);
+ if (pa != NULL) {
+ while (idx < accounts.getCount() && !ProtoToInclude(accounts[idx]))
+ idx++;
+ pa->iOrder = idx++;
+ if (ppd->enabled)
+ pa->bIsVisible = ppd->show != 0;
}
-
- WriteDbAccounts();
- cli.pfnReloadProtoMenus();
- cli.pfnTrayIconIconsChanged();
- cli.pfnClcBroadcast(INTM_RELOADOPTIONS, 0, 0);
- cli.pfnClcBroadcast(INTM_INVALIDATE, 0, 0);
}
- break;
- case IDC_PROTOCOLORDER:
- switch (((LPNMHDR)lParam)->code) {
- case TVN_DELETEITEM:
- {
- NMTREEVIEWA * pnmtv = (NMTREEVIEWA *) lParam;
- if (pnmtv && pnmtv->itemOld.lParam)
- mir_free((ProtocolData*)pnmtv->itemOld.lParam);
- }
- break;
+ tvi.hItem = m_order.GetNextSibling(tvi.hItem);
+ }
- case TVN_BEGINDRAG:
- SetCapture(hwndDlg);
- dat->dragging = 1;
- dat->hDragItem = ((LPNMTREEVIEW)lParam)->itemNew.hItem;
- TreeView_SelectItem(hwndProtoOrder, dat->hDragItem);
- break;
+ WriteDbAccounts();
+ cli.pfnReloadProtoMenus();
+ cli.pfnTrayIconIconsChanged();
+ cli.pfnClcBroadcast(INTM_RELOADOPTIONS, 0, 0);
+ cli.pfnClcBroadcast(INTM_INVALIDATE, 0, 0);
+ }
+ virtual void OnDestroy()
+ {
+ ImageList_Destroy(m_order.GetImageList(TVSIL_NORMAL));
+ }
+
+ void onReset_Click(CCtrlButton*)
+ {
+ for (int i = 0; i < accounts.getCount(); i++)
+ accounts[i]->iOrder = i;
+
+ FillTree();
+ NotifyChange();
+ }
+
+ void onOrder_DeleteItem(CCtrlTreeView::TEventInfo *env)
+ {
+ NMTREEVIEW *pnmtv = env->nmtv;
+ if (pnmtv)
+ mir_free((ProtocolData*)pnmtv->itemOld.lParam);
+ }
+
+ void onOrder_BeginDrag(CCtrlTreeView::TEventInfo *env)
+ {
+ SetCapture(m_hwnd);
+ m_bDragging = true;
+ m_hDragItem = env->nmtv->itemNew.hItem;
+ m_order.SelectItem(m_hDragItem);
+ }
+
+ virtual INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
+ {
+ TVHITTESTINFO hti;
+
+ switch (msg) {
+ case WM_NOTIFY:
+ switch (((LPNMHDR)lParam)->code) {
case NM_CLICK:
- {
- TVHITTESTINFO hti;
- hti.pt.x = (short)LOWORD(GetMessagePos());
- hti.pt.y = (short)HIWORD(GetMessagePos());
- ScreenToClient(((LPNMHDR)lParam)->hwndFrom, &hti.pt);
- if (TreeView_HitTest(((LPNMHDR)lParam)->hwndFrom, &hti)) {
- if (hti.flags & TVHT_ONITEMICON) {
- TVITEMA tvi;
- tvi.mask = TVIF_HANDLE|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
- tvi.hItem = hti.hItem;
- TreeView_GetItem(((LPNMHDR)lParam)->hwndFrom, &tvi);
-
- ProtocolData *pData = (ProtocolData*)tvi.lParam;
- if (pData->enabled) {
- tvi.iImage = tvi.iSelectedImage = !tvi.iImage;
- pData->show = tvi.iImage;
- TreeView_SetItem(((LPNMHDR)lParam)->hwndFrom, &tvi);
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, (WPARAM)hwndDlg, 0);
- }
+ hti.pt.x = (short)LOWORD(GetMessagePos());
+ hti.pt.y = (short)HIWORD(GetMessagePos());
+ ScreenToClient(((LPNMHDR)lParam)->hwndFrom, &hti.pt);
+ if (m_order.HitTest(&hti)) {
+ if (hti.flags & TVHT_ONITEMICON) {
+ TVITEMEX tvi;
+ tvi.mask = TVIF_HANDLE | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
+ tvi.hItem = hti.hItem;
+ m_order.GetItem(&tvi);
+
+ ProtocolData *pData = (ProtocolData*)tvi.lParam;
+ if (pData->enabled) {
+ tvi.iImage = tvi.iSelectedImage = !tvi.iImage;
+ pData->show = tvi.iImage;
+ m_order.SetItem(&tvi);
+ NotifyChange();
}
}
}
}
break;
- }
- break;
- case WM_MOUSEMOVE:
- if (dat->dragging) {
- TVHITTESTINFO hti;
+ case WM_MOUSEMOVE:
+ if (!m_bDragging)
+ break;
+
hti.pt.x = (short)LOWORD(lParam);
hti.pt.y = (short)HIWORD(lParam);
- ClientToScreen(hwndDlg, &hti.pt);
- ScreenToClient(hwndProtoOrder, &hti.pt);
- TreeView_HitTest(hwndProtoOrder, &hti);
- if (hti.flags & (TVHT_ONITEM|TVHT_ONITEMRIGHT)) {
+ ClientToScreen(m_hwnd, &hti.pt);
+ ScreenToClient(m_order.GetHwnd(), &hti.pt);
+ m_order.HitTest(&hti);
+ if (hti.flags & (TVHT_ONITEM | TVHT_ONITEMRIGHT)) {
HTREEITEM it = hti.hItem;
- hti.pt.y -= TreeView_GetItemHeight(hwndProtoOrder) / 2;
- TreeView_HitTest(hwndProtoOrder, &hti);
+ hti.pt.y -= m_order.GetItemHeight() / 2;
+ m_order.HitTest(&hti);
if (!(hti.flags & TVHT_ABOVE))
- TreeView_SetInsertMark(hwndProtoOrder, hti.hItem, 1);
+ m_order.SetInsertMark(hti.hItem, 1);
else
- TreeView_SetInsertMark(hwndProtoOrder, it, 0);
+ m_order.SetInsertMark(it, 0);
}
else {
- if (hti.flags&TVHT_ABOVE) SendMessage(hwndProtoOrder, WM_VSCROLL, MAKEWPARAM(SB_LINEUP, 0), 0);
- if (hti.flags&TVHT_BELOW) SendMessage(hwndProtoOrder, WM_VSCROLL, MAKEWPARAM(SB_LINEDOWN, 0), 0);
- TreeView_SetInsertMark(hwndProtoOrder, NULL, 0);
+ if (hti.flags & TVHT_ABOVE) m_order.SendMsg(WM_VSCROLL, MAKEWPARAM(SB_LINEUP, 0), 0);
+ if (hti.flags & TVHT_BELOW) m_order.SendMsg(WM_VSCROLL, MAKEWPARAM(SB_LINEDOWN, 0), 0);
+ m_order.SetInsertMark(NULL, 0);
}
- }
- break;
+ break;
- case WM_LBUTTONUP:
- if (dat->dragging) {
- TreeView_SetInsertMark(hwndProtoOrder, NULL, 0);
- dat->dragging = 0;
+ case WM_LBUTTONUP:
+ if (!m_bDragging)
+ break;
+
+ m_order.SetInsertMark(NULL, 0);
+ m_bDragging = false;
ReleaseCapture();
- TVHITTESTINFO hti;
hti.pt.x = (short)LOWORD(lParam);
hti.pt.y = (short)HIWORD(lParam);
- ClientToScreen(hwndDlg, &hti.pt);
- ScreenToClient(hwndProtoOrder, &hti.pt);
- hti.pt.y -= TreeView_GetItemHeight(hwndProtoOrder) / 2;
- TreeView_HitTest(hwndProtoOrder, &hti);
- if (dat->hDragItem == hti.hItem) break;
+ ClientToScreen(m_hwnd, &hti.pt);
+ ScreenToClient(m_order.GetHwnd(), &hti.pt);
+ hti.pt.y -= m_order.GetItemHeight() / 2;
+ m_order.HitTest(&hti);
+ if (m_hDragItem == hti.hItem)
+ break;
if (hti.flags & TVHT_ABOVE)
hti.hItem = TVI_FIRST;
- TVITEM tvi;
- tvi.mask = TVIF_HANDLE|TVIF_PARAM;
- tvi.hItem = dat->hDragItem;
- TreeView_GetItem(hwndProtoOrder, &tvi);
+ TVITEMEX tvi;
+ tvi.mask = TVIF_HANDLE | TVIF_PARAM;
+ tvi.hItem = m_hDragItem;
+ m_order.GetItem(&tvi);
if (hti.flags & (TVHT_ONITEM | TVHT_ONITEMRIGHT) || (hti.hItem == TVI_FIRST)) {
- TVINSERTSTRUCT tvis;
TCHAR name[128];
- ProtocolData * lpOldData;
- tvis.item.mask = TVIF_HANDLE|TVIF_PARAM|TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
- tvis.item.stateMask = 0xFFFFFFFF;
- tvis.item.pszText = name;
- tvis.item.cchTextMax = SIZEOF(name);
- tvis.item.hItem = dat->hDragItem;
- tvis.item.iImage = tvis.item.iSelectedImage = ((ProtocolData *)tvi.lParam)->show;
- TreeView_GetItem(hwndProtoOrder, &tvis.item);
-
- //the pointed lParam will be freed inside TVN_DELETEITEM
- //so lets substitute it with 0
- lpOldData = (ProtocolData *)tvis.item.lParam;
- tvis.item.lParam = 0;
- TreeView_SetItem(hwndProtoOrder, &tvis.item);
- tvis.item.lParam = (LPARAM)lpOldData;
-
- //now current item contain lParam = 0 we can delete it. the memory will be kept.
- TreeView_DeleteItem(hwndProtoOrder, dat->hDragItem);
+ TVINSERTSTRUCT tvis;
+ tvis.itemex.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
+ tvis.itemex.stateMask = 0xFFFFFFFF;
+ tvis.itemex.pszText = name;
+ tvis.itemex.cchTextMax = SIZEOF(name);
+ tvis.itemex.hItem = m_hDragItem;
+ tvis.itemex.iImage = tvis.itemex.iSelectedImage = ((ProtocolData *)tvi.lParam)->show;
+ m_order.GetItem(&tvis.itemex);
+
+ // the pointed lParam will be freed inside TVN_DELETEITEM
+ // so lets substitute it with 0
+ ProtocolData *lpOldData = (ProtocolData*)tvis.itemex.lParam;
+ tvis.itemex.lParam = 0;
+ m_order.SetItem(&tvis.itemex);
+
+ // now current item contain lParam = 0 we can delete it. the memory will be kept.
+ tvis.itemex.lParam = (LPARAM)lpOldData;
+ m_order.DeleteItem(m_hDragItem);
tvis.hParent = NULL;
tvis.hInsertAfter = hti.hItem;
- TreeView_SelectItem(hwndProtoOrder, TreeView_InsertItem(hwndProtoOrder, &tvis));
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, (WPARAM)hwndDlg, 0);
+ m_order.SelectItem(m_order.InsertItem(&tvis));
+ NotifyChange();
}
}
- break;
-
- case WM_DESTROY:
- ImageList_Destroy(TreeView_GetImageList(hwndProtoOrder, TVSIL_NORMAL));
- mir_free(dat);
- break;
+ return CDlgBase::DlgProc(msg, wParam, lParam);
}
- return FALSE;
+};
+
+int ProtocolOrderOptInit(WPARAM wParam, LPARAM)
+{
+ OPTIONSDIALOGPAGE odp = { 0 }; + odp.position = -10000000; + odp.groupPosition = 1000000; + odp.pszTitle = LPGEN("Accounts"); + odp.pszGroup = LPGEN("Contact list"); + odp.pDialog = new CProtocolOrderOpts(); + odp.flags = ODPF_BOLDGROUPS; + Options_AddPage(wParam, &odp); + return 0;
}
|