diff options
Diffstat (limited to 'plugins/ClientChangeNotify')
14 files changed, 1386 insertions, 1507 deletions
diff --git a/plugins/ClientChangeNotify/ClientChangeNotify.vcxproj b/plugins/ClientChangeNotify/ClientChangeNotify.vcxproj index 29dee9e7a4..e9ee42c0f3 100644 --- a/plugins/ClientChangeNotify/ClientChangeNotify.vcxproj +++ b/plugins/ClientChangeNotify/ClientChangeNotify.vcxproj @@ -26,23 +26,6 @@ <Import Project="$(ProjectDir)..\..\build\vc.common\plugin.props" />
</ImportGroup>
<ItemGroup>
- <ClCompile Include="src\CommonLibs\CString.cpp">
- <PrecompiledHeaderFile>../stdafx.h</PrecompiledHeaderFile>
- </ClCompile>
- <ClCompile Include="src\CommonLibs\Options.cpp">
- <PrecompiledHeaderFile>../stdafx.h</PrecompiledHeaderFile>
- </ClCompile>
- <ClCompile Include="src\CommonLibs\pcre.cpp">
- <PrecompiledHeaderFile>../stdafx.h</PrecompiledHeaderFile>
- </ClCompile>
- </ItemGroup>
- <ItemGroup>
- <ClInclude Include="src\CommonLibs\CString.h" />
- <ClInclude Include="src\CommonLibs\Options.h" />
- <ClInclude Include="src\CommonLibs\pcre.h" />
- <ClInclude Include="src\CommonLibs\TMyArray.h" />
- </ItemGroup>
- <ItemGroup>
<ProjectReference Include="..\..\libs\Pcre16\pcre16.vcxproj">
<Project>{6124e997-426e-4a0b-9617-d6d577d5e7d7}</Project>
</ProjectReference>
diff --git a/plugins/ClientChangeNotify/src/CommonLibs/CString.cpp b/plugins/ClientChangeNotify/src/CString.cpp index fafe50b8a3..8cb1208896 100644 --- a/plugins/ClientChangeNotify/src/CommonLibs/CString.cpp +++ b/plugins/ClientChangeNotify/src/CString.cpp @@ -17,7 +17,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "../stdafx.h"
+#include "stdafx.h"
#include "CString.h"
#define STR_GROWBY 64
diff --git a/plugins/ClientChangeNotify/src/CommonLibs/CString.h b/plugins/ClientChangeNotify/src/CString.h index 9218a6459d..9218a6459d 100644 --- a/plugins/ClientChangeNotify/src/CommonLibs/CString.h +++ b/plugins/ClientChangeNotify/src/CString.h diff --git a/plugins/ClientChangeNotify/src/ClientChangeNotify.cpp b/plugins/ClientChangeNotify/src/ClientChangeNotify.cpp index 66e0e89785..59034b59a6 100644 --- a/plugins/ClientChangeNotify/src/ClientChangeNotify.cpp +++ b/plugins/ClientChangeNotify/src/ClientChangeNotify.cpp @@ -163,13 +163,13 @@ void ShowPopup(SHOWPOPUP_DATA *sd) char *szProto = GetContactProto(sd->hContact);
pdata->hIcon = ppd.lchIcon = Finger_GetClientIcon(sd->MirVer, false);
_ASSERT(ppd.lchIcon);
- if (!ppd.lchIcon || (DWORD)ppd.lchIcon == CALLSERVICE_NOTFOUND) {
+ if (!ppd.lchIcon || (INT_PTR)ppd.lchIcon == CALLSERVICE_NOTFOUND) {
// if we didn't succeed retrieving client icon, show the usual status icon instead
ppd.lchIcon = Skin_LoadProtoIcon(szProto, db_get_w(sd->hContact, szProto, "Status", ID_STATUS_OFFLINE));
pdata->hIcon = NULL;
}
- _tcsncpy(ppd.lptzContactName, (TCHAR*)pcli->pfnGetContactDisplayName(sd->hContact, 0), lengthof(ppd.lptzContactName) - 1);
- _tcsncpy(ppd.lptzText, PopupText, lengthof(ppd.lptzText) - 1);
+ _tcsncpy(ppd.lptzContactName, (TCHAR*)pcli->pfnGetContactDisplayName(sd->hContact, 0), _countof(ppd.lptzContactName) - 1);
+ _tcsncpy(ppd.lptzText, PopupText, _countof(ppd.lptzText) - 1);
ppd.colorBack = (sd->PopupOptPage->GetValue(IDC_POPUPOPTDLG_DEFBGCOLOUR) ? 0 : sd->PopupOptPage->GetValue(IDC_POPUPOPTDLG_BGCOLOUR));
ppd.colorText = (sd->PopupOptPage->GetValue(IDC_POPUPOPTDLG_DEFTEXTCOLOUR) ? 0 : sd->PopupOptPage->GetValue(IDC_POPUPOPTDLG_TEXTCOLOUR));
ppd.PluginWindowProc = PopupWndProc;
diff --git a/plugins/ClientChangeNotify/src/CommonLibs/Options.cpp b/plugins/ClientChangeNotify/src/CommonLibs/Options.cpp deleted file mode 100644 index f83c9265b3..0000000000 --- a/plugins/ClientChangeNotify/src/CommonLibs/Options.cpp +++ /dev/null @@ -1,963 +0,0 @@ -/*
- Options.cpp
- Copyright (c) 2005-2008 Chervov Dmitry
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-*/
-
-#include "../stdafx.h"
-#include "Options.h"
-
-static CString sEmptyString("");
-
-
-COptPage::COptPage(const COptPage &Item)
-{
- *this = Item;
-}
-
-COptPage::~COptPage()
-{
- int I;
- for (I = 0; I < Items.GetSize(); I++)
- {
- delete Items[I];
- }
- Items.RemoveAll();
-}
-
-void COptPage::MemToPage(int OnlyEnable)
-{
- int I;
- _ASSERT(hWnd);
- for (I = 0; I < Items.GetSize(); I++)
- {
- if (OnlyEnable)
- {
- Items[I]->COptItem::MemToWnd(hWnd);
- } else
- {
- Items[I]->MemToWnd(hWnd);
- }
- }
-}
-
-void COptPage::PageToMem()
-{
- int I;
- _ASSERT(hWnd);
- for (I = 0; I < Items.GetSize(); I++)
- {
- Items[I]->WndToMem(hWnd);
- }
-}
-
-void COptPage::DBToMem()
-{
- int I;
- _ASSERT(sModule != "");
- for (I = 0; I < Items.GetSize(); I++)
- {
- Items[I]->DBToMem(sModule, &sDBSettingPrefix);
- }
-}
-
-void COptPage::MemToDB()
-{
- int I;
- _ASSERT(sModule != "");
- for (I = 0; I < Items.GetSize(); I++)
- {
- Items[I]->MemToDB(sModule, &sDBSettingPrefix);
- }
-}
-
-void COptPage::CleanDBSettings()
-{
- int I;
- _ASSERT(sModule != "");
- for (I = 0; I < Items.GetSize(); I++)
- {
- Items[I]->CleanDBSettings(sModule, &sDBSettingPrefix);
- }
-}
-
-bool COptPage::GetModified()
-{
- int I;
- _ASSERT(sModule != "");
- for (I = 0; I < Items.GetSize(); I++)
- {
- if (Items[I]->GetModified())
- {
- return true;
- }
- }
- return false;
-}
-
-void COptPage::SetModified(bool Modified)
-{
- int I;
- _ASSERT(sModule != "");
- for (I = 0; I < Items.GetSize(); I++)
- {
- Items[I]->SetModified(Modified);
- }
-}
-
-COptItem *COptPage::Find(int DlgItemID)
-{
- int I;
- for (I = 0; I < Items.GetSize(); I++)
- {
- if (Items[I]->GetID() == DlgItemID)
- {
- return Items[I];
- }
- }
- _ASSERT(0);
- return 0;
-}
-
-COptPage& COptPage::operator = (const COptPage& Page)
-{
- int I;
- hWnd = Page.hWnd;
- sModule = Page.sModule;
- sDBSettingPrefix = Page.sDBSettingPrefix;
- Items.RemoveAll();
- for (I = 0; I < Page.Items.GetSize(); I++)
- {
- Items.AddElem(Page.Items[I]->Copy());
- }
- return *this;
-}
-
-
-int COptItem::GetIntDBVal(CString &sModule, int bSigned, CString*)
-{ // default procedure for reading value from DB; used only for integral types
- if (sDBSetting != NULL)
- {
- _ASSERT(nValueSize == DBVT_BYTE || nValueSize == DBVT_WORD || nValueSize == DBVT_DWORD);
- DBVARIANT dbv;
- if (db_get(NULL, sModule, sDBSetting, &dbv))
- return GetDefValue();
-
- return (nValueSize == DBVT_BYTE) ? (bSigned ? (signed char)dbv.bVal : (unsigned char)dbv.bVal) : ((nValueSize == DBVT_WORD) ? (bSigned ? (signed short)dbv.wVal : (unsigned short)dbv.wVal) : dbv.dVal);
- }
- return GetDefValue();
-}
-
-void COptItem::SetIntDBVal(CString &sModule, int Value, CString*)
-{ // default procedure for writing value to the DB; used only for integral types
- if (sDBSetting != NULL && !ReadOnly)
- {
- _ASSERT(nValueSize == DBVT_BYTE || nValueSize == DBVT_WORD || nValueSize == DBVT_DWORD);
-
- DBVARIANT dbv;
- dbv.type = nValueSize;
- dbv.dVal = Value;
- db_set(NULL, sModule, sDBSetting, &dbv);
- }
-}
-
-TCString COptItem::GetStrDBVal(CString &sModule, CString *sDBSettingPrefix)
-{
- if (sDBSetting != NULL)
- {
- _ASSERT(GetDefValue());
- return db_get_s(NULL, sModule, sDBSettingPrefix ? (*sDBSettingPrefix + sDBSetting) : sDBSetting, *(TCString*)GetDefValue());
- }
- return *(TCString*)GetDefValue();
-}
-
-void COptItem::SetStrDBVal(CString &sModule, TCString &Str, CString *sDBSettingPrefix)
-{
- if (sDBSetting != NULL && !ReadOnly)
- {
- db_set_ts(NULL, sModule, sDBSettingPrefix ? (*sDBSettingPrefix + sDBSetting) : sDBSetting, Str);
- }
-}
-
-
-
-void COptItem_Checkbox::DBToMem(CString &sModule, CString *sDBSettingPrefix)
-{
- if (ValueMask)
- {
- Value = (GetIntDBVal(sModule, false, sDBSettingPrefix) & ValueMask) ? BST_CHECKED : BST_UNCHECKED;
- } else
- {
- Value = GetIntDBVal(sModule, false, sDBSettingPrefix);
- }
- COptItem::DBToMem(sModule, sDBSettingPrefix);
-}
-
-void COptItem_Checkbox::MemToDB(CString &sModule, CString *sDBSettingPrefix)
-{
- if (ValueMask)
- {
- if (Value == BST_CHECKED)
- {
- SetIntDBVal(sModule, GetIntDBVal(sModule, false, sDBSettingPrefix) | ValueMask, sDBSettingPrefix);
- } else
- {
- SetIntDBVal(sModule, GetIntDBVal(sModule, false, sDBSettingPrefix) & ~ValueMask, sDBSettingPrefix);
- }
- } else
- {
- SetIntDBVal(sModule, Value, sDBSettingPrefix);
- }
- COptItem::MemToDB(sModule, sDBSettingPrefix);
-}
-
-void COptItem_Checkbox::WndToMem(HWND hWnd)
-{
- Value = IsDlgButtonChecked(hWnd, DlgItemID);
-// tri-state checkboxes in combination with ValueMask != 0 are not supported ;)
- _ASSERT(!ValueMask || Value != BST_INDETERMINATE);
- COptItem::WndToMem(hWnd);
-}
-
-void COptItem_Checkbox::MemToWnd(HWND hWnd)
-{
- CheckDlgButton(hWnd, DlgItemID, Value ? BST_CHECKED : BST_UNCHECKED);
- COptItem::MemToWnd(hWnd);
-}
-
-
-
-void COptItem_BitDBSetting::DBToMem(CString &sModule, CString *sDBSettingPrefix)
-{
- if (ValueMask)
- {
- Value = (GetIntDBVal(sModule, false, sDBSettingPrefix) & ValueMask) != 0;
- } else
- {
- Value = GetIntDBVal(sModule, false, sDBSettingPrefix);
- }
- COptItem::DBToMem(sModule, sDBSettingPrefix);
-}
-
-void COptItem_BitDBSetting::MemToDB(CString &sModule, CString *sDBSettingPrefix)
-{
- if (ValueMask)
- {
- if (Value)
- {
- SetIntDBVal(sModule, GetIntDBVal(sModule, false, sDBSettingPrefix) | ValueMask, sDBSettingPrefix);
- } else
- {
- SetIntDBVal(sModule, GetIntDBVal(sModule, false, sDBSettingPrefix) & ~ValueMask, sDBSettingPrefix);
- }
- } else
- {
- SetIntDBVal(sModule, Value, sDBSettingPrefix);
- }
- COptItem::MemToDB(sModule, sDBSettingPrefix);
-}
-
-
-// ================================================ COptItem_TreeCtrl ================================================
-
-int COptItem_TreeCtrl::IDToOrder(int ID)
-{
- int I;
- for (I = 0; I < RootItems.GetSize(); I++)
- {
- if (RootItems[I].ID == ID)
- {
- return ROOT_INDEX_TO_ORDER(I);
- }
- }
- for (I = 0; I < Value.GetSize(); I++)
- {
- if (Value[I].ID == ID)
- {
- return I;
- }
- }
- return -1;
-}
-
-int COptItem_TreeCtrl::hItemToOrder(HTREEITEM hItem)
-{
- int I;
- for (I = 0; I < RootItems.GetSize(); I++)
- {
- if (RootItems[I].hItem == hItem)
- {
- return ROOT_INDEX_TO_ORDER(I);
- }
- }
- for (I = 0; I < Value.GetSize(); I++)
- {
- if (Value[I].hItem == hItem)
- {
- return I;
- }
- }
- return -1;
-}
-
-int COptItem_TreeCtrl::GenerateID()
-{
- int ID = 0;
- while (IDToOrder(ID) != -1)
- {
- ID++;
- }
- return ID;
-}
-
-typedef struct
-{
- COptItem_TreeCtrl *TreeCtrl;
- CString *sModule;
- CString *sDBSettingPrefix;
-} sTreeReadEnumData;
-
-int TreeReadEnum(const char *szSetting, LPARAM lParam)
-{
- sTreeReadEnumData *TreeReadEnumData = (sTreeReadEnumData*)lParam;
- int Len = TreeReadEnumData->TreeCtrl->sDBSetting.GetLen() + lengthof(TREEITEM_DBSTR_TITLE) - 1;
- if (!strncmp(szSetting, TreeReadEnumData->TreeCtrl->sDBSetting + TREEITEM_DBSTR_TITLE, Len) && isdigit(szSetting[Len]))
- {
- int ID = atol(szSetting + Len);
- short ParentID = (TreeReadEnumData->TreeCtrl->TreeFlags & TREECTRL_FLAG_IS_SINGLE_LEVEL) ? 0 : db_get_w(NULL, *TreeReadEnumData->sModule,
- *TreeReadEnumData->sDBSettingPrefix + TreeReadEnumData->TreeCtrl->sDBSetting + TREEITEM_DBSTR_PARENT + (szSetting + Len), -1);
- short Order = db_get_w(NULL, *TreeReadEnumData->sModule,
- *TreeReadEnumData->sDBSettingPrefix + TreeReadEnumData->TreeCtrl->sDBSetting + TREEITEM_DBSTR_ORDER + (szSetting + Len), -1);
- char Flags = (TreeReadEnumData->TreeCtrl->TreeFlags & TREECTRL_FLAG_IS_SINGLE_LEVEL && !(TreeReadEnumData->TreeCtrl->TreeFlags & TREECTRL_FLAG_HAS_CHECKBOXES)) ? 0 : db_get_b(NULL, *TreeReadEnumData->sModule,
- *TreeReadEnumData->sDBSettingPrefix + TreeReadEnumData->TreeCtrl->sDBSetting + TREEITEM_DBSTR_FLAGS + (szSetting + Len), 0);
- if (ParentID >= 0 && Order >= 0)
- {
- TreeReadEnumData->TreeCtrl->Value.SetAtGrow(Order).ID = ID;
- TreeReadEnumData->TreeCtrl->Value.SetAtGrow(Order).ParentID = ParentID;
- TreeReadEnumData->TreeCtrl->Value.SetAtGrow(Order).Flags = Flags;
- TreeReadEnumData->TreeCtrl->Value.SetAtGrow(Order).hItem = NULL;
- TreeReadEnumData->TreeCtrl->Value.SetAtGrow(Order).Title = db_get_s(NULL, *TreeReadEnumData->sModule, *TreeReadEnumData->sDBSettingPrefix + szSetting, _T(""));
- TreeReadEnumData->TreeCtrl->Value.SetAtGrow(Order).User_Str1 = (TreeReadEnumData->TreeCtrl->User_Str1_DBName == NULL) ? NULL :
- db_get_s(NULL, *TreeReadEnumData->sModule,
- *TreeReadEnumData->sDBSettingPrefix + TreeReadEnumData->TreeCtrl->sDBSetting + TreeReadEnumData->TreeCtrl->User_Str1_DBName + (szSetting + Len), (TCHAR*)NULL);
- }
- }
- return 0;
-}
-
-void COptItem_TreeCtrl::DBToMem(CString &sModule, CString *sDBSettingPrefix)
-{
- if (!sDBSettingPrefix)
- {
- sDBSettingPrefix = &sEmptyString;
- }
- Value.RemoveAll();
- sTreeReadEnumData TreeReadEnumData;
- TreeReadEnumData.TreeCtrl = this;
- TreeReadEnumData.sModule = &sModule;
- TreeReadEnumData.sDBSettingPrefix = sDBSettingPrefix;
- DBCONTACTENUMSETTINGS dbEnum;
- dbEnum.lParam = (LPARAM)&TreeReadEnumData;
- dbEnum.ofsSettings = 0;
- dbEnum.pfnEnumProc = TreeReadEnum;
- dbEnum.szModule = sModule;
- CallService(MS_DB_CONTACT_ENUMSETTINGS, NULL, (LPARAM)&dbEnum);
- if (!Value.GetSize())
- {
- Value = DefValue;
- } else
- {
- int I;
- for (I = 0; I < Value.GetSize(); I++)
- {
- if (Value[I].Title == NULL)
- {
- Value.RemoveElem(I);
- I--;
- }
- }
- }
- COptItem::DBToMem(sModule, sDBSettingPrefix);
-}
-
-void COptItem_TreeCtrl::MemToDB(CString &sModule, CString *sDBSettingPrefix)
-{
- if (!ReadOnly && Modified)
- {
- if (!sDBSettingPrefix)
- {
- sDBSettingPrefix = &sEmptyString;
- }
- CleanDBSettings(sModule, sDBSettingPrefix);
- int I;
- for (I = 0; I < Value.GetSize(); I++)
- {
- CString StrID;
- _itoa(Value[I].ID, StrID.GetBuffer(64), 10);
- StrID.ReleaseBuffer();
- db_set_ts(NULL, sModule, *sDBSettingPrefix + sDBSetting + TREEITEM_DBSTR_TITLE + StrID, Value[I].Title);
- if (!(TreeFlags & TREECTRL_FLAG_IS_SINGLE_LEVEL))
- db_set_w(NULL, sModule, *sDBSettingPrefix + sDBSetting + TREEITEM_DBSTR_PARENT + StrID, Value[I].ParentID);
-
- db_set_w(NULL, sModule, *sDBSettingPrefix + sDBSetting + TREEITEM_DBSTR_ORDER + StrID, I);
- if (!(TreeFlags & TREECTRL_FLAG_IS_SINGLE_LEVEL) || TreeFlags & TREECTRL_FLAG_HAS_CHECKBOXES)
- db_set_b(NULL, sModule, *sDBSettingPrefix + sDBSetting + TREEITEM_DBSTR_FLAGS + StrID, Value[I].Flags);
-
- if (User_Str1_DBName != NULL && Value[I].User_Str1 != NULL)
- db_set_ts(NULL, sModule, *sDBSettingPrefix + sDBSetting + User_Str1_DBName + StrID, Value[I].User_Str1);
- }
- COptItem::MemToDB(sModule, sDBSettingPrefix);
- }
-}
-
-void COptItem_TreeCtrl::WndToMem(HWND hWnd)
-{ // only need to gather info of items state (expanded/collapsed, checked/unchecked)
- HWND hTreeView = GetDlgItem(hWnd, DlgItemID);
- int I;
- for (I = 0; I < Value.GetSize(); I++)
- {
- DWORD State = TreeView_GetItemState(hTreeView, Value[I].hItem, TVIS_EXPANDED | TVIS_STATEIMAGEMASK);
- int OldFlags = Value[I].Flags;
- if (State & TVIS_EXPANDED)
- {
- Value[I].Flags |= TIF_EXPANDED;
- } else
- {
- Value[I].Flags &= ~TIF_EXPANDED;
- }
- if (TreeFlags & TREECTRL_FLAG_HAS_CHECKBOXES && (State >> 12) - 1)
- {
- Value[I].Flags |= TIF_ENABLED;
- } else
- {
- Value[I].Flags &= ~TIF_ENABLED;
- }
- if (Value[I].Flags != OldFlags)
- {
- Modified = true;
- }
- }
- COptItem::WndToMem(hWnd);
-}
-
-void COptItem_TreeCtrl::MemToWnd(HWND hWnd)
-{
- HWND hTreeView = GetDlgItem(hWnd, DlgItemID);
- if (TreeFlags & TREECTRL_FLAG_HAS_CHECKBOXES)
- { // have to set this in run-time as it's specified in MSDN
- LONG_PTR Style = GetWindowLongPtr(hTreeView, GWL_STYLE);
- SetWindowLongPtr(hTreeView, GWL_STYLE, Style & ~TVS_CHECKBOXES);
- SetWindowLongPtr(hTreeView, GWL_STYLE, Style | TVS_CHECKBOXES);
- }
- TVINSERTSTRUCT tvIn = {0};
- int ScrollPos = GetScrollPos(hTreeView, SB_VERT);
- int SelectOrder = IDToOrder(GetSelectedItemID(hWnd));
- SendMessage(hTreeView, WM_SETREDRAW, false, 0);
- TreeView_DeleteAllItems(hTreeView);
- _ASSERT(RootItems.GetSize());
- int I;
- if (!(TreeFlags & TREECTRL_FLAG_IS_SINGLE_LEVEL))
- {
- for (I = 0; I < RootItems.GetSize(); I++)
- {
- tvIn.item.mask = TVIF_TEXT | TVIF_STATE | TVIF_PARAM;
- RootItems[I].Flags |= TIF_GROUP;
- tvIn.item.state = tvIn.item.stateMask = TVIS_BOLD | ((RootItems[I].Flags & TIF_EXPANDED) ? TVIS_EXPANDED : 0);
- tvIn.item.pszText = RootItems[I].Title;
- tvIn.hParent = TVI_ROOT;
- tvIn.hInsertAfter = TVI_LAST;
- tvIn.item.lParam = RootItems[I].ID;
- RootItems[I].hItem = TreeView_InsertItem(hTreeView, &tvIn);
- }
- }
- for (I = 0; I < Value.GetSize(); I++)
- {
- Value[I].hItem = RootItems[0].hItem; // put an item to first group in case of some strange error
- }
- for (I = 0; I < Value.GetSize(); I++)
- {
- tvIn.item.mask = TVIF_TEXT | TVIF_STATE | TVIF_PARAM;
- tvIn.item.state = tvIn.item.stateMask = (Value[I].Flags & TIF_GROUP) ? (TVIS_BOLD | ((Value[I].Flags & TIF_EXPANDED) ? TVIS_EXPANDED : 0)) : 0;
- if (TreeFlags & TREECTRL_FLAG_HAS_CHECKBOXES)
- {
- tvIn.item.stateMask |= TVIS_STATEIMAGEMASK;
- tvIn.item.state |= INDEXTOSTATEIMAGEMASK((Value[I].Flags & TIF_ENABLED) ? 2 : 1);
- }
- tvIn.item.pszText = Value[I].Title;
- int Order = IDToOrder(Value[I].ParentID);
- if (Order != -1)
- {
- tvIn.hParent = (Order <= TREECTRL_ROOTORDEROFFS) ? RootItems[ROOT_ORDER_TO_INDEX(Order)].hItem : Value[Order].hItem;
- tvIn.hInsertAfter = TVI_LAST;
- tvIn.item.lParam = Value[I].ID;
- Value[I].hItem = TreeView_InsertItem(hTreeView, &tvIn);
- } else
- { // found an orphan item; probably it's better just to delete it
- Value.RemoveElem(I);
- I--;
- }
- }
- TreeView_SelectItem(hTreeView, (SelectOrder >= 0) ? Value[SelectOrder].hItem : ((SelectOrder <= TREECTRL_ROOTORDEROFFS) ? RootItems[ROOT_ORDER_TO_INDEX(SelectOrder)].hItem : NULL));
- SendMessage(hTreeView, WM_SETREDRAW, true, 0);
- SCROLLBARINFO sbi;
- sbi.cbSize = sizeof(sbi);
- GetScrollBarInfo(hTreeView, OBJID_VSCROLL, &sbi);
- if (!(sbi.rgstate[0] & STATE_SYSTEM_INVISIBLE))
- {
- int MinPos, MaxPos;
- GetScrollRange(hTreeView, SB_VERT, &MinPos, &MaxPos);
- if (ScrollPos < MinPos)
- {
- ScrollPos = MinPos;
- } else if (ScrollPos > MaxPos)
- {
- ScrollPos = MaxPos;
- }
- SetScrollPos(hTreeView, SB_VERT, ScrollPos, true);
- }
- COptItem::MemToWnd(hWnd);
-}
-
-
-typedef struct
-{
- TMyArray<CString> TreeSettings;
- COptItem_TreeCtrl *TreeCtrl;
- CString *sDBSettingPrefix;
-} sTreeDeleteEnumData;
-
-int TreeDeleteEnum(const char *szSetting, LPARAM lParam)
-{
- sTreeDeleteEnumData *TreeDeleteEnumData = (sTreeDeleteEnumData*)lParam;
- CString CurSetting;
- CurSetting = *TreeDeleteEnumData->sDBSettingPrefix + TreeDeleteEnumData->TreeCtrl->sDBSetting + TREEITEM_DBSTR_TITLE;
- if (!strncmp(szSetting, CurSetting, CurSetting.GetLen()))
- {
- TreeDeleteEnumData->TreeSettings.AddElem(szSetting);
- }
- CurSetting = *TreeDeleteEnumData->sDBSettingPrefix + TreeDeleteEnumData->TreeCtrl->sDBSetting + TREEITEM_DBSTR_PARENT;
- if (!strncmp(szSetting, CurSetting, CurSetting.GetLen()))
- {
- TreeDeleteEnumData->TreeSettings.AddElem(szSetting);
- }
- CurSetting = *TreeDeleteEnumData->sDBSettingPrefix + TreeDeleteEnumData->TreeCtrl->sDBSetting + TREEITEM_DBSTR_ORDER;
- if (!strncmp(szSetting, CurSetting, CurSetting.GetLen()))
- {
- TreeDeleteEnumData->TreeSettings.AddElem(szSetting);
- }
- CurSetting = *TreeDeleteEnumData->sDBSettingPrefix + TreeDeleteEnumData->TreeCtrl->sDBSetting + TREEITEM_DBSTR_FLAGS;
- if (!strncmp(szSetting, CurSetting, CurSetting.GetLen()))
- {
- TreeDeleteEnumData->TreeSettings.AddElem(szSetting);
- }
- if (TreeDeleteEnumData->TreeCtrl->User_Str1_DBName != NULL)
- {
- CurSetting = *TreeDeleteEnumData->sDBSettingPrefix + TreeDeleteEnumData->TreeCtrl->sDBSetting + TreeDeleteEnumData->TreeCtrl->User_Str1_DBName;
- if (!strncmp(szSetting, CurSetting, CurSetting.GetLen()))
- {
- TreeDeleteEnumData->TreeSettings.AddElem(szSetting);
- }
- }
- return 0;
-}
-
-void COptItem_TreeCtrl::CleanDBSettings(CString &sModule, CString *sDBSettingPrefix)
-{
- if (!sDBSettingPrefix)
- {
- sDBSettingPrefix = &sEmptyString;
- }
- sTreeDeleteEnumData TreeDeleteEnumData;
- TreeDeleteEnumData.TreeCtrl = this;
- TreeDeleteEnumData.sDBSettingPrefix = sDBSettingPrefix;
- DBCONTACTENUMSETTINGS dbEnum;
- dbEnum.lParam = (LPARAM)&TreeDeleteEnumData;
- dbEnum.ofsSettings = 0;
- dbEnum.pfnEnumProc = TreeDeleteEnum;
- dbEnum.szModule = sModule;
- CallService(MS_DB_CONTACT_ENUMSETTINGS, NULL, (LPARAM)&dbEnum);
- int I;
- for (I = 0; I < TreeDeleteEnumData.TreeSettings.GetSize(); I++)
- {
- db_unset(NULL, sModule, TreeDeleteEnumData.TreeSettings[I]);
- }
-}
-
-
-int COptItem_TreeCtrl::GetSelectedItemID(HWND hWnd)
-{
- HWND hTreeView = GetDlgItem(hWnd, DlgItemID);
- TVITEM tvi = {0};
- tvi.hItem = TreeView_GetSelection(hTreeView);
- if (!tvi.hItem)
- {
- return -1;
- }
- tvi.mask = TVIF_HANDLE | TVIF_PARAM;
- TreeView_GetItem(hTreeView, &tvi);
- return tvi.lParam;
-}
-
-void COptItem_TreeCtrl::Delete(HWND hWnd, int ID)
-{
- int SelectedOrder = IDToOrder(ID);
- _ASSERT(SelectedOrder >= 0);
- RecursiveDelete(hWnd, SelectedOrder);
- Modified = true;
-}
-
-void COptItem_TreeCtrl::RecursiveDelete(HWND hWnd, int I)
-{
- if (Value[I].Flags & TIF_GROUP)
- {
- int J;
- for (J = I + 1; J < Value.GetSize(); J++)
- {
- if (Value[J].ParentID == Value[I].ID)
- {
- RecursiveDelete(hWnd, J--);
- }
- }
- }
- HWND hTreeView = GetDlgItem(hWnd, DlgItemID);
- TreeView_DeleteItem(hTreeView, Value[I].hItem);
- Value.RemoveElem(I);
-}
-
-CTreeItem* COptItem_TreeCtrl::InsertItem(HWND hWnd, CTreeItem &Item)
-// Item's ID and ParentID are not used (the new item position is determined by current selection in the tree)
-// returns a pointer to the newly inserted item info
-{
- _ASSERT(!(TreeFlags & TREECTRL_FLAG_IS_SINGLE_LEVEL) || !(Item.Flags & TIF_GROUP));
- HWND hTreeView = GetDlgItem(hWnd, DlgItemID);
- TVITEM tvi;
- int SelOrder = -1;
- Item.ParentID = RootItems[0].ID;
- TVINSERTSTRUCT tvIn = {0};
- tvIn.hParent = RootItems[0].hItem;
- tvIn.hInsertAfter = TVI_FIRST;
- if (tvi.hItem = TreeView_GetSelection(hTreeView))
- {
- tvi.mask = TVIF_HANDLE | TVIF_PARAM;
- TreeView_GetItem(hTreeView, &tvi);
- SelOrder = IDToOrder(tvi.lParam);
- if (SelOrder <= TREECTRL_ROOTORDEROFFS)
- {
- Item.ParentID = RootItems[ROOT_ORDER_TO_INDEX(SelOrder)].ID;
- tvIn.hParent = RootItems[ROOT_ORDER_TO_INDEX(SelOrder)].hItem;
- SelOrder = -1;
- } else
- {
- if (Value[SelOrder].Flags & TIF_GROUP)
- {
- Item.ParentID = Value[SelOrder].ID;
- tvIn.hParent = Value[SelOrder].hItem;
- } else
- {
- Item.ParentID = Value[SelOrder].ParentID;
- int Order = IDToOrder(Value[SelOrder].ParentID);
- tvIn.hParent = (Order <= TREECTRL_ROOTORDEROFFS) ? RootItems[ROOT_ORDER_TO_INDEX(Order)].hItem : Value[Order].hItem;
- tvIn.hInsertAfter = Value[SelOrder].hItem;
- }
- }
- }
- tvIn.item.mask = TVIF_TEXT | TVIF_STATE | TVIF_PARAM;
- tvIn.item.state = tvIn.item.stateMask = (Item.Flags & TIF_GROUP) ? (TVIS_BOLD |
- ((Item.Flags & TIF_EXPANDED) ? TVIS_EXPANDED : 0)) : 0;
- if (TreeFlags & TREECTRL_FLAG_HAS_CHECKBOXES)
- {
- tvIn.item.stateMask |= TVIS_STATEIMAGEMASK;
- tvIn.item.state |= INDEXTOSTATEIMAGEMASK((Item.Flags & TIF_ENABLED) ? 2 : 1);
- }
- tvIn.item.pszText = Item.Title;
- tvIn.item.lParam = Item.ID = GenerateID();
- Value.InsertElem(Item, SelOrder + 1);
- Value[SelOrder + 1].hItem = TreeView_InsertItem(hTreeView, &tvIn);
- TreeView_SelectItem(hTreeView, Value[SelOrder + 1].hItem);
- Modified = true;
- return &Value[SelOrder + 1];
-}
-
-int COptItem_TreeCtrl::RecursiveMove(int ItemOrder, int ParentID, int InsertAtOrder)
-// ItemOrder must be a movable item (i.e. ItemOrder >= 0)
-// InsertAtOrder must be >= 0 too.
-{
- int ItemsMoved = 1;
- Value.MoveElem(ItemOrder, InsertAtOrder);
- Value[InsertAtOrder].ParentID = ParentID;
- if (Value[InsertAtOrder].Flags & TIF_GROUP) // need to ensure that no items were left before their group by an order.
- {
- int GroupID = Value[InsertAtOrder].ID;
- int I;
- for (I = ItemOrder; I < InsertAtOrder; I++) // if ItemOrder > InsertAtOrder then there is simply nothing to do
- {
- if (Value[I].ParentID == GroupID)
- {
- int CurrentItemsMoved = RecursiveMove(I, GroupID, InsertAtOrder);
- ItemsMoved += CurrentItemsMoved;
- InsertAtOrder -= CurrentItemsMoved;
- I--;
- }
- }
- }
- return ItemsMoved;
-}
-
-void COptItem_TreeCtrl::MoveItem(HWND hWnd, HTREEITEM hItem, HTREEITEM hMoveTo)
-{ // hMoveTo can be NULL and it means that we must move hItem to the beginning of the list
- _ASSERT(hItem && (hMoveTo || TreeFlags & TREECTRL_FLAG_IS_SINGLE_LEVEL));
- if (hItem == hMoveTo)
- {
- return;
- }
- HWND hTreeView = GetDlgItem(hWnd, DlgItemID);
- TVITEM tvi;
- tvi.mask = TVIF_HANDLE | TVIF_PARAM;
- tvi.hItem = hItem;
- TreeView_GetItem(hTreeView, &tvi);
- int ItemOrder = IDToOrder(tvi.lParam);
- _ASSERT(ItemOrder != -1);
- int MoveToOrder;
- if (hMoveTo)
- {
- tvi.hItem = hMoveTo;
- TreeView_GetItem(hTreeView, &tvi);
- MoveToOrder = IDToOrder(tvi.lParam);
- _ASSERT(MoveToOrder != -1);
- } else
- {
- MoveToOrder = -1;
- }
- if (ItemOrder <= TREECTRL_ROOTORDEROFFS)
- {
- return; // can't move root items
- }
- if (Value[ItemOrder].Flags & TIF_GROUP)
- { // need to check for a case when trying to move a group to its own subgroup.
- int Order = MoveToOrder;
- while (Order >= 0)
- {
- Order = IDToOrder(Value[Order].ParentID);
- if (Order == ItemOrder)
- {
- return;
- }
- }
- }
-// well, everything is ok, we really can move that item.
- WndToMem(hWnd); // save groups state (expanded/collapsed)
- if (MoveToOrder != -1 && ((MoveToOrder <= TREECTRL_ROOTORDEROFFS) ? RootItems[ROOT_ORDER_TO_INDEX(MoveToOrder)].Flags : Value[MoveToOrder].Flags) & TIF_GROUP)
- { // if the destination is a group, then move the item to that group
- RecursiveMove(ItemOrder, (MoveToOrder <= TREECTRL_ROOTORDEROFFS) ? RootItems[ROOT_ORDER_TO_INDEX(MoveToOrder)].ID : Value[MoveToOrder].ID, (MoveToOrder >= 0) ? ((ItemOrder < MoveToOrder) ? MoveToOrder : (MoveToOrder + 1)) : 0);
- } else
- { // else place the item after the destination item
- RecursiveMove(ItemOrder, (MoveToOrder == -1) ? 0 : Value[MoveToOrder].ParentID, (ItemOrder < MoveToOrder) ? MoveToOrder : (MoveToOrder + 1)); // when TREECTRL_FLAG_IS_SINGLE_LEVEL, we always have a root item with ID = 0.
- }
- MemToWnd(hWnd); // update the tree
- Modified = true;
-}
-
-
-// ================================================ COptItem_ListCtrl ================================================
-
-typedef struct
-{
- COptItem_ListCtrl *ListCtrl;
- CString *sModule;
- CString *sDBSettingPrefix;
-} sListReadEnumData;
-
-int ListReadEnum(const char *szSetting, LPARAM lParam)
-{
- sListReadEnumData *ListReadEnumData = (sListReadEnumData*)lParam;
- int Len = ListReadEnumData->sDBSettingPrefix->GetLen() + ListReadEnumData->ListCtrl->sDBSetting.GetLen() + lengthof(LISTITEM_DBSTR_TEXT) - 1;
- if (!strncmp(szSetting, *ListReadEnumData->sDBSettingPrefix + ListReadEnumData->ListCtrl->sDBSetting + LISTITEM_DBSTR_TEXT, Len) && isdigit(szSetting[Len]))
- {
- int ID = atol(szSetting + Len);
- ListReadEnumData->ListCtrl->Value.SetAtGrow(ID).Text = db_get_s(NULL, *ListReadEnumData->sModule, *ListReadEnumData->sDBSettingPrefix + szSetting, _T(""));
- }
- return 0;
-}
-
-void COptItem_ListCtrl::DBToMem(CString &sModule, CString *sDBSettingPrefix)
-{
- if (!sDBSettingPrefix)
- {
- sDBSettingPrefix = &sEmptyString;
- }
- Value.RemoveAll();
- sListReadEnumData ListReadEnumData;
- ListReadEnumData.ListCtrl = this;
- ListReadEnumData.sModule = &sModule;
- ListReadEnumData.sDBSettingPrefix = sDBSettingPrefix;
- DBCONTACTENUMSETTINGS dbEnum;
- dbEnum.lParam = (LPARAM)&ListReadEnumData;
- dbEnum.ofsSettings = 0;
- dbEnum.pfnEnumProc = ListReadEnum;
- dbEnum.szModule = sModule;
- CallService(MS_DB_CONTACT_ENUMSETTINGS, NULL, (LPARAM)&dbEnum);
- if (!Value.GetSize())
- {
- Value = DefValue;
- } else
- {
- int I;
- for (I = 0; I < Value.GetSize(); I++)
- {
- if (Value[I].Text == NULL) // NULL is not ""!
- {
- Value.RemoveElem(I);
- I--;
- }
- }
- }
- COptItem::DBToMem(sModule, sDBSettingPrefix);
-}
-
-void COptItem_ListCtrl::MemToDB(CString &sModule, CString *sDBSettingPrefix)
-{
- if (!ReadOnly && Modified)
- {
- if (!sDBSettingPrefix)
- {
- sDBSettingPrefix = &sEmptyString;
- }
- CleanDBSettings(sModule, sDBSettingPrefix);
- int I;
- for (I = 0; I < Value.GetSize(); I++)
- {
- CString StrID;
- _itoa(I, StrID.GetBuffer(64), 10);
- StrID.ReleaseBuffer();
- db_set_ts(NULL, sModule, *sDBSettingPrefix + sDBSetting + LISTITEM_DBSTR_TEXT + StrID, Value[I].Text);
- }
- COptItem::MemToDB(sModule, sDBSettingPrefix);
- }
-}
-
-void COptItem_ListCtrl::WndToMem(HWND hWnd)
-{
-// nothing to do
- COptItem::WndToMem(hWnd);
-}
-
-void COptItem_ListCtrl::MemToWnd(HWND hWnd)
-{
- HWND hListView = GetDlgItem(hWnd, DlgItemID);
- SendMessage(hListView, WM_SETREDRAW, false, 0);
- SendMessage(hListView, LB_RESETCONTENT, 0, 0);
- int I;
- for (I = 0; I < Value.GetSize(); I++)
- {
- SendMessage(hListView, LB_INSERTSTRING, -1, (LPARAM)(TCHAR*)Value[I].Text);
- }
- SendMessage(hListView, WM_SETREDRAW, true, 0);
- COptItem::MemToWnd(hWnd);
-}
-
-
-typedef struct
-{
- TMyArray<CString> ListSettings;
- COptItem_ListCtrl *ListCtrl;
- CString *sDBSettingPrefix;
-} sListDeleteEnumData;
-
-int ListDeleteEnum(const char *szSetting, LPARAM lParam)
-{
- sListDeleteEnumData *ListDeleteEnumData = (sListDeleteEnumData*)lParam;
- CString CurSetting = *ListDeleteEnumData->sDBSettingPrefix + ListDeleteEnumData->ListCtrl->sDBSetting + LISTITEM_DBSTR_TEXT;
- if (!strncmp(szSetting, CurSetting, CurSetting.GetLen()))
- {
- ListDeleteEnumData->ListSettings.AddElem(szSetting);
- }
- return 0;
-}
-
-void COptItem_ListCtrl::CleanDBSettings(CString &sModule, CString *sDBSettingPrefix)
-{
- if (!sDBSettingPrefix)
- {
- sDBSettingPrefix = &sEmptyString;
- }
- sListDeleteEnumData ListDeleteEnumData;
- ListDeleteEnumData.ListCtrl = this;
- ListDeleteEnumData.sDBSettingPrefix = sDBSettingPrefix;
- DBCONTACTENUMSETTINGS dbEnum;
- dbEnum.lParam = (LPARAM)&ListDeleteEnumData;
- dbEnum.ofsSettings = 0;
- dbEnum.pfnEnumProc = ListDeleteEnum;
- dbEnum.szModule = sModule;
- CallService(MS_DB_CONTACT_ENUMSETTINGS, NULL, (LPARAM)&dbEnum);
- int I;
- for (I = 0; I < ListDeleteEnumData.ListSettings.GetSize(); I++)
- {
- db_unset(NULL, sModule, ListDeleteEnumData.ListSettings[I]);
- }
-}
-
-
-int COptItem_ListCtrl::GetSelectedItemID(HWND hWnd)
-{
- int Res = SendDlgItemMessage(hWnd, DlgItemID, LB_GETCURSEL, 0, 0);
- return (Res == LB_ERR) ? -1 : Res; // I know that LB_ERR = -1 ;)
-}
-
-int COptItem_ListCtrl::SetSelectedItemID(HWND hWnd, int ID)
-{
- int Res = SendDlgItemMessage(hWnd, DlgItemID, LB_SETCURSEL, ID, 0);
- return (Res == LB_ERR) ? -1 : Res;
-}
-
-void COptItem_ListCtrl::Delete(HWND hWnd, int ID)
-{
- _ASSERT(ID >= 0);
- HWND hListView = GetDlgItem(hWnd, DlgItemID);
- int Res = SendMessage(hListView, LB_DELETESTRING, ID, 0);
- _ASSERT(Res != LB_ERR);
- Value.RemoveElem(ID);
- Modified = true;
-}
-
-void COptItem_ListCtrl::ModifyItem(HWND hWnd, int ID, CListItem &Item)
-{ // changes the text of item with the specified ID
- _ASSERT(ID >= 0);
- HWND hListView = GetDlgItem(hWnd, DlgItemID);
- SendMessage(hListView, WM_SETREDRAW, false, 0);
- int CurSel = SendMessage(hListView, LB_GETCURSEL, 0, 0);
- int TopIndex = SendMessage(hListView, LB_GETTOPINDEX, 0, 0);
- int Res = SendMessage(hListView, LB_DELETESTRING, ID, 0);
- _ASSERT(Res != LB_ERR);
- Res = SendMessage(hListView, LB_INSERTSTRING, ID, (LPARAM)(TCHAR*)(Item.Text));
- _ASSERT(Res != LB_ERR && Res != LB_ERRSPACE);
- SendMessage(hListView, LB_SETCURSEL, CurSel, 0);
- SendMessage(hListView, LB_SETTOPINDEX, TopIndex, 0);
- SendMessage(hListView, WM_SETREDRAW, true, 0);
- Value[ID].Text = Item.Text;
- Modified = true;
-}
-
-CListItem* COptItem_ListCtrl::InsertItem(HWND hWnd, int ID, CListItem &Item)
-// returns a pointer to the newly inserted item info
-// ID is position at which to insert the item; -1 = add to the end of the list
-{
- HWND hListView = GetDlgItem(hWnd, DlgItemID);
- int Res = SendMessage(hListView, LB_INSERTSTRING, ID, (LPARAM)(TCHAR*)(Item.Text)); // LB_INSERTSTRING doesn't sort the lists even with LBS_SORT style
- _ASSERT(Res != LB_ERR && Res != LB_ERRSPACE);
- int I = Value.AddElem(Item);
- Modified = true;
- return &Value[I];
-}
diff --git a/plugins/ClientChangeNotify/src/CommonLibs/Options.h b/plugins/ClientChangeNotify/src/CommonLibs/Options.h deleted file mode 100644 index 5d429b8a8a..0000000000 --- a/plugins/ClientChangeNotify/src/CommonLibs/Options.h +++ /dev/null @@ -1,481 +0,0 @@ -/*
- Options.h
- Copyright (c) 2005-2008 Chervov Dmitry
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-*/
-
-#pragma once
-
-#include "CString.h"
-#include "TMyArray.h"
-
-#ifndef lengthof
-#define lengthof(s) (sizeof(s) / sizeof(*s))
-#endif
-
-
-class COptItem
-{
-public:
- COptItem() {}
- COptItem(int DlgItemID, char *szDBSetting, int nValueSize, int lParam = 0, bool ReadOnly = false):
- DlgItemID(DlgItemID), nValueSize(nValueSize), sDBSetting(szDBSetting), lParam(lParam), Enabled(true), ReadOnly(ReadOnly), Modified(false) {}
- virtual ~COptItem() {}
-
- virtual void DBToMem(CString&, CString* = NULL) { Modified = false; }
- virtual void MemToDB(CString&, CString* = NULL) { Modified = false; }
- virtual void WndToMem(HWND) {}
- virtual void MemToWnd(HWND hWnd) {EnableWindow(GetDlgItem(hWnd, DlgItemID), Enabled);}
- void DBToMemToWnd(CString &sModule, HWND hWnd, CString *sDBSettingPrefix = NULL) {DBToMem(sModule, sDBSettingPrefix); MemToWnd(hWnd);}
- void WndToMemToDB(HWND hWnd, CString &sModule, CString *sDBSettingPrefix = NULL) {WndToMem(hWnd); MemToDB(sModule, sDBSettingPrefix);}
- virtual void CleanDBSettings(CString &sModule, CString *sDBSettingPrefix = NULL) {db_unset(NULL, sModule, sDBSettingPrefix ? (*sDBSettingPrefix + sDBSetting) : sDBSetting);}; // TODO: also set Value to DefValue?
-
- virtual void SetValue(int) {Modified = true;}
- virtual void SetDefValue(int) {}
- virtual int GetValue() {return 0;}
- virtual int GetDefValue() {return 0;}
- int GetDBValue(CString &sModule, CString *sDBSettingPrefix = NULL) {DBToMem(sModule, sDBSettingPrefix); return GetValue();}
- void SetDBValue(CString &sModule, int Value, CString *sDBSettingPrefix = NULL) {SetValue(Value); MemToDB(sModule, sDBSettingPrefix);}
- int GetDBValueCopy(CString &sModule, CString *sDBSettingPrefix = NULL) {COptItem* Item = Copy(); Item->DBToMem(sModule, sDBSettingPrefix); int Value = Item->GetValue(); delete Item; return Value;} // retrieves DB value, but doesn't affect current page/item state; beware! it doesn't work with string values / other dynamic pointers
- void SetDBValueCopy(CString &sModule, int Value, CString *sDBSettingPrefix = NULL) {COptItem* Item = Copy(); Item->SetValue(Value); Item->MemToDB(sModule, sDBSettingPrefix); delete Item;}
- int GetWndValue(HWND hWnd) {WndToMem(hWnd); return GetValue();}
- void SetWndValue(HWND hWnd, int Value) {SetValue(Value); MemToWnd(hWnd);}
- void SetDlgItemID(int DlgItemID) {this->DlgItemID = DlgItemID;}
- bool GetModified() {return Modified;}
- void SetModified(bool Modified) {this->Modified = Modified;}
-
- void Enable(int Enabled) {this->Enabled = Enabled;}
- int GetParam() {return lParam;}
- int GetID() {return DlgItemID;}
-
-// virtual COptItem& operator = (const COptItem& Item) {return *this;};
- virtual COptItem* Copy() {_ASSERT(0); return NULL;} // Attention! Free Copy() result when it's not needed anymore!
-
- CString sDBSetting;
-
-protected:
- int GetIntDBVal(CString &sModule, int bSigned = false, CString *sDBSettingPrefix = NULL);
- void SetIntDBVal(CString &sModule, int Value, CString *sDBSettingPrefix = NULL);
- TCString GetStrDBVal(CString &sModule, CString *sDBSettingPrefix = NULL);
- void SetStrDBVal(CString &sModule, TCString &Str, CString *sDBSettingPrefix = NULL);
-
- int DlgItemID;
- int Enabled;
- bool ReadOnly;
- bool Modified;
- int nValueSize; // maximum pValue size in bytes
- int lParam;
-};
-
-
-class COptItem_Generic : public COptItem
-{
-public:
- COptItem_Generic() {}
- COptItem_Generic(int DlgItemID, int lParam = 0): COptItem(DlgItemID, NULL, 0, lParam) {}
- virtual COptItem* Copy() {return new COptItem_Generic(*this);}
-};
-
-
-class COptItem_Edit : public COptItem
-{
-public:
- COptItem_Edit() {}
- COptItem_Edit(int DlgItemID, char *szDBSetting, int nMaxLen, TCHAR *szDefValue, int lParam = 0, bool ReadOnly = false): COptItem(DlgItemID, szDBSetting, nMaxLen, lParam, ReadOnly), sDefValue(szDefValue) {}
-// COptItem_Edit(const COptItem_Edit &Item): sDefValue(Item.sDefValue), sValue(Item.sValue) {}
- void DBToMem(CString &sModule, CString *sDBSettingPrefix = NULL) {sValue = GetStrDBVal(sModule, sDBSettingPrefix); COptItem::DBToMem(sModule, sDBSettingPrefix);}
- void MemToDB(CString &sModule, CString *sDBSettingPrefix = NULL) {SetStrDBVal(sModule, sValue, sDBSettingPrefix); COptItem::MemToDB(sModule, sDBSettingPrefix);}
- void WndToMem(HWND hWnd) {GetDlgItemText(hWnd, DlgItemID, sValue.GetBuffer(nValueSize), nValueSize); sValue.ReleaseBuffer(); COptItem::MemToWnd(hWnd);}
- void MemToWnd(HWND hWnd) {SetDlgItemText(hWnd, DlgItemID, sValue); COptItem::MemToWnd(hWnd);}
- void SetValue(int Value) {sValue = *(TCString*)Value; COptItem::SetValue(Value);}
- void SetDefValue(int DefValue) {sDefValue = *(TCString*)DefValue; COptItem::SetDefValue(DefValue);}
- int GetValue() {return (int)&sValue;}
- int GetDefValue() {return (int)&sDefValue;}
-
-// COptItem_Edit& operator = (const COptItem_Edit& Item) {return *this;};
- virtual COptItem* Copy() {return new COptItem_Edit(*this);}
-
- TCString sDefValue;
- TCString sValue;
-};
-
-
-class COptItem_IntEdit : public COptItem
-{
-public:
- COptItem_IntEdit() {}
- COptItem_IntEdit(int DlgItemID, char *szDBSetting, int nValueSize = DBVT_BYTE, int bSigned = true, int DefValue = 0, int lParam = 0, bool ReadOnly = false): COptItem(DlgItemID, szDBSetting, nValueSize, lParam, ReadOnly), DefValue(DefValue), Value(0), bSigned(bSigned) {}
- void DBToMem(CString &sModule, CString *sDBSettingPrefix = NULL) {Value = GetIntDBVal(sModule, bSigned, sDBSettingPrefix); COptItem::DBToMem(sModule, sDBSettingPrefix);}
- void MemToDB(CString &sModule, CString *sDBSettingPrefix = NULL) {SetIntDBVal(sModule, Value, sDBSettingPrefix); COptItem::MemToDB(sModule, sDBSettingPrefix);}
- void WndToMem(HWND hWnd) {Value = GetDlgItemInt(hWnd, DlgItemID, NULL, bSigned); COptItem::WndToMem(hWnd);}
- void MemToWnd(HWND hWnd) {SetDlgItemInt(hWnd, DlgItemID, Value, bSigned); COptItem::MemToWnd(hWnd);}
- void SetValue(int Value) {this->Value = Value; COptItem::SetValue(Value);}
- void SetDefValue(int DefValue) {this->DefValue = DefValue; COptItem::SetDefValue(DefValue);}
- int GetValue() {return Value;}
- int GetDefValue() {return DefValue;}
- virtual COptItem* Copy() {return new COptItem_IntEdit(*this);}
-
- int DefValue;
- int Value;
- int bSigned;
-};
-
-
-class COptItem_Checkbox : public COptItem
-{
-public:
- COptItem_Checkbox() {}
- COptItem_Checkbox(int DlgItemID, char *szDBSetting, int nValueSize = DBVT_BYTE, int DefValue = 0, int ValueMask = 0, int lParam = 0, bool ReadOnly = false): COptItem(DlgItemID, szDBSetting, nValueSize, lParam, ReadOnly), DefValue(DefValue), Value(0), ValueMask(ValueMask) {}
-
- void DBToMem(CString &sModule, CString *sDBSettingPrefix = NULL);
- void MemToDB(CString &sModule, CString *sDBSettingPrefix = NULL);
- void WndToMem(HWND hWnd);
- void MemToWnd(HWND hWnd);
-
- void SetValue(int Value) {this->Value = Value; COptItem::SetValue(Value);}
- void SetDefValue(int DefValue) {this->DefValue = DefValue; COptItem::SetDefValue(DefValue);}
- int GetValue() {return Value;}
- int GetDefValue() {return DefValue;}
- virtual COptItem* Copy() {return new COptItem_Checkbox(*this);}
-
- int Value;
- int DefValue;
- int ValueMask;
-};
-
-
-class COptItem_Radiobutton : public COptItem
-{
-public:
- COptItem_Radiobutton() {}
- COptItem_Radiobutton(int DlgItemID, char *szDBSetting, int nValueSize, int DefValue, int ValueMask, int lParam = 0, bool ReadOnly = false): COptItem(DlgItemID, szDBSetting, nValueSize, lParam, ReadOnly), DefValue(DefValue), Value(0), ValueMask(ValueMask) {}
-
- void DBToMem(CString &sModule, CString *sDBSettingPrefix = NULL) {Value = (GetIntDBVal(sModule, false, sDBSettingPrefix) == ValueMask) ? BST_CHECKED : BST_UNCHECKED; COptItem::DBToMem(sModule, sDBSettingPrefix);}
- void MemToDB(CString &sModule, CString *sDBSettingPrefix = NULL) {if ((Value == BST_CHECKED)) SetIntDBVal(sModule, ValueMask, sDBSettingPrefix); COptItem::MemToDB(sModule, sDBSettingPrefix);}
- void WndToMem(HWND hWnd) {Value = IsDlgButtonChecked(hWnd, DlgItemID); COptItem::WndToMem(hWnd);}
- void MemToWnd(HWND hWnd) {CheckDlgButton(hWnd, DlgItemID, Value ? BST_CHECKED : BST_UNCHECKED); COptItem::MemToWnd(hWnd);}
-
- void SetValue(int Value) {this->Value = Value; COptItem::SetValue(Value);}
- void SetDefValue(int DefValue) {this->DefValue = DefValue; COptItem::SetDefValue(DefValue);}
- int GetValue() {return Value;}
- int GetDefValue() {return DefValue;}
- virtual COptItem* Copy() {return new COptItem_Radiobutton(*this);}
-
- int Value;
- int DefValue;
- int ValueMask;
-};
-
-
-class COptItem_Combobox : public COptItem
-{
-public:
- COptItem_Combobox() {}
- COptItem_Combobox(int DlgItemID, char *szDBSetting, int nValueSize = DBVT_BYTE, int DefValue = 0, int lParam = 0, bool ReadOnly = false): COptItem(DlgItemID, szDBSetting, nValueSize, lParam, ReadOnly), DefValue(DefValue), Value(0) {}
- void DBToMem(CString &sModule, CString *sDBSettingPrefix = NULL) {Value = GetIntDBVal(sModule, false, sDBSettingPrefix); COptItem::DBToMem(sModule, sDBSettingPrefix);}
- void MemToDB(CString &sModule, CString *sDBSettingPrefix = NULL) {SetIntDBVal(sModule, Value, sDBSettingPrefix); COptItem::MemToDB(sModule, sDBSettingPrefix);}
- void WndToMem(HWND hWnd) {Value = SendDlgItemMessage(hWnd, DlgItemID, CB_GETITEMDATA, (WPARAM)SendDlgItemMessage(hWnd, DlgItemID, CB_GETCURSEL, 0, 0), 0); COptItem::WndToMem(hWnd);}
- void MemToWnd(HWND hWnd) {SendDlgItemMessage(hWnd, DlgItemID, CB_SETCURSEL, Value, 0); COptItem::MemToWnd(hWnd);}
- void SetValue(int Value) {this->Value = Value; COptItem::SetValue(Value);}
- void SetDefValue(int DefValue) {this->DefValue = DefValue; COptItem::SetDefValue(DefValue);}
- int GetValue() {return Value;}
- int GetDefValue() {return DefValue;}
- virtual COptItem* Copy() {return new COptItem_Combobox(*this);}
-
- int DefValue;
- int Value;
-};
-
-
-class COptItem_Colourpicker : public COptItem
-{
-public:
- COptItem_Colourpicker() {}
- COptItem_Colourpicker(int DlgItemID, char *szDBSetting, int DefValue = 0, int lParam = 0, bool ReadOnly = false): COptItem(DlgItemID, szDBSetting, DBVT_DWORD, lParam, ReadOnly), DefValue(DefValue), Value(0) {}
- void DBToMem(CString &sModule, CString *sDBSettingPrefix = NULL) {Value = GetIntDBVal(sModule, false, sDBSettingPrefix); COptItem::DBToMem(sModule, sDBSettingPrefix);}
- void MemToDB(CString &sModule, CString *sDBSettingPrefix = NULL) {SetIntDBVal(sModule, Value, sDBSettingPrefix); COptItem::MemToDB(sModule, sDBSettingPrefix);}
- void WndToMem(HWND hWnd) {Value = SendDlgItemMessage(hWnd, DlgItemID, CPM_GETCOLOUR, 0, 0); COptItem::WndToMem(hWnd);}
- void MemToWnd(HWND hWnd) {SendDlgItemMessage(hWnd, DlgItemID, CPM_SETCOLOUR, 0, Value); COptItem::MemToWnd(hWnd);}
- void SetValue(int Value) {this->Value = Value; COptItem::SetValue(Value);}
- void SetDefValue(int DefValue) {this->DefValue = DefValue; COptItem::SetDefValue(DefValue);}
- int GetValue() {return Value;}
- int GetDefValue() {return DefValue;}
- virtual COptItem* Copy() {return new COptItem_Colourpicker(*this);}
-
- DWORD DefValue;
- DWORD Value;
-};
-
-
-class COptItem_Slider : public COptItem
-{
-public:
- COptItem_Slider() {}
- COptItem_Slider(int DlgItemID, char *szDBSetting, int nValueSize = DBVT_BYTE, int DefValue = 0, int lParam = 0, bool ReadOnly = false): COptItem(DlgItemID, szDBSetting, nValueSize, lParam, ReadOnly), DefValue(DefValue), Value(0) {}
- void DBToMem(CString &sModule, CString *sDBSettingPrefix = NULL) {Value = GetIntDBVal(sModule, false, sDBSettingPrefix); COptItem::DBToMem(sModule, sDBSettingPrefix);}
- void MemToDB(CString &sModule, CString *sDBSettingPrefix = NULL) {SetIntDBVal(sModule, Value, sDBSettingPrefix); COptItem::MemToDB(sModule, sDBSettingPrefix);}
- void WndToMem(HWND hWnd) {Value = SendDlgItemMessage(hWnd, DlgItemID, TBM_GETPOS, 0, 0); COptItem::WndToMem(hWnd);}
- void MemToWnd(HWND hWnd) {SendDlgItemMessage(hWnd, DlgItemID, TBM_SETPOS, true, Value); COptItem::MemToWnd(hWnd);}
- void SetValue(int Value) {this->Value = Value; COptItem::SetValue(Value);}
- void SetDefValue(int DefValue) {this->DefValue = DefValue; COptItem::SetDefValue(DefValue);}
- int GetValue() {return Value;}
- int GetDefValue() {return DefValue;}
- virtual COptItem* Copy() {return new COptItem_Slider(*this);}
-
- int DefValue;
- int Value;
-};
-
-
-class COptItem_IntDBSetting : public COptItem
-{
-public:
- COptItem_IntDBSetting() {}
- COptItem_IntDBSetting(int DlgItemID, char *szDBSetting, int nValueSize = DBVT_BYTE, int bSigned = true, int DefValue = 0, int lParam = 0, bool ReadOnly = false): COptItem(DlgItemID, szDBSetting, nValueSize, lParam, ReadOnly), DefValue(DefValue), Value(0), bSigned(bSigned) {}
- void DBToMem(CString &sModule, CString *sDBSettingPrefix = NULL) {Value = GetIntDBVal(sModule, bSigned, sDBSettingPrefix); COptItem::DBToMem(sModule, sDBSettingPrefix);}
- void MemToDB(CString &sModule, CString *sDBSettingPrefix = NULL) {SetIntDBVal(sModule, Value, sDBSettingPrefix); COptItem::MemToDB(sModule, sDBSettingPrefix);}
- void WndToMem(HWND hWnd) {COptItem::WndToMem(hWnd);}
- void MemToWnd(HWND hWnd) {COptItem::MemToWnd(hWnd);}
- void SetValue(int Value) {this->Value = Value; COptItem::SetValue(Value);}
- void SetDefValue(int DefValue) {this->DefValue = DefValue; COptItem::SetDefValue(DefValue);}
- int GetValue() {return Value;}
- int GetDefValue() {return DefValue;}
- virtual COptItem* Copy() {return new COptItem_IntDBSetting(*this);}
-
- int Value;
- int DefValue;
- int bSigned;
-};
-
-
-class COptItem_BitDBSetting : public COptItem
-{
-public:
- COptItem_BitDBSetting() {}
- COptItem_BitDBSetting(int DlgItemID, char *szDBSetting, int nValueSize = DBVT_BYTE, int DefValue = 0, int ValueMask = 0, int lParam = 0, bool ReadOnly = false): COptItem(DlgItemID, szDBSetting, nValueSize, lParam, ReadOnly), DefValue(DefValue), Value(0), ValueMask(ValueMask) {}
-
- void DBToMem(CString &sModule, CString *sDBSettingPrefix = NULL);
- void MemToDB(CString &sModule, CString *sDBSettingPrefix = NULL);
- void WndToMem(HWND hWnd) {COptItem::WndToMem(hWnd);}
- void MemToWnd(HWND hWnd) {COptItem::MemToWnd(hWnd);}
-
- void SetValue(int Value) {this->Value = Value; COptItem::SetValue(Value);}
- void SetDefValue(int DefValue) {this->DefValue = DefValue; COptItem::SetDefValue(DefValue);}
- int GetValue() {return Value;}
- int GetDefValue() {return DefValue;}
- virtual COptItem* Copy() {return new COptItem_BitDBSetting(*this);}
-
- int Value;
- int DefValue;
- int ValueMask;
-};
-
-
-class COptItem_StrDBSetting : public COptItem
-{
-public:
- COptItem_StrDBSetting() {}
- COptItem_StrDBSetting(int DlgItemID, char *szDBSetting, int nMaxLen, TCHAR *szDefValue, int lParam = 0, bool ReadOnly = false): COptItem(DlgItemID, szDBSetting, nMaxLen, lParam, ReadOnly), sDefValue(szDefValue) {}
- void DBToMem(CString &sModule, CString *sDBSettingPrefix = NULL) {sValue = GetStrDBVal(sModule, sDBSettingPrefix); COptItem::DBToMem(sModule, sDBSettingPrefix);}
- void MemToDB(CString &sModule, CString *sDBSettingPrefix = NULL) {SetStrDBVal(sModule, sValue, sDBSettingPrefix); COptItem::MemToDB(sModule, sDBSettingPrefix);}
- void WndToMem(HWND hWnd) {COptItem::WndToMem(hWnd);}
- void MemToWnd(HWND hWnd) {COptItem::MemToWnd(hWnd);}
- void SetValue(int Value) {sValue = *(TCString*)Value; COptItem::SetValue(Value);}
- void SetDefValue(int DefValue) {sDefValue = *(TCString*)DefValue; COptItem::SetDefValue(DefValue);}
- int GetValue() {return (int)&sValue;}
- int GetDefValue() {return (int)&sDefValue;}
- virtual COptItem* Copy() {return new COptItem_StrDBSetting(*this);}
-
- TCString sDefValue;
- TCString sValue;
-};
-
-
-// Tree item flags
-#define TIF_GROUP 1 // is a group
-#define TIF_EXPANDED 2 // item is expanded
-#define TIF_ENABLED 4 // item is checked (has sense when the tree has checkboxes)
-#define TIF_ROOTITEM 0x80 // item is a root item
-
-class CBaseTreeItem
-{
-public:
- CBaseTreeItem();
- CBaseTreeItem(TCString Title, int ID, int Flags): Title(Title), ID(ID), Flags(Flags), hItem(NULL) {}
-
- TCString Title;
- int ID;
- int Flags;
- HTREEITEM hItem;
-};
-
-class CTreeItem : public CBaseTreeItem
-{
-public:
- CTreeItem();
- CTreeItem(TCString Title, int ParentID, int ID, int Flags = 0, TCString User_Str1 = NULL):
- CBaseTreeItem(Title, ID, Flags & ~TIF_ROOTITEM), ParentID(ParentID), User_Str1(User_Str1) {}
-
- int ParentID;
- TCString User_Str1;
-};
-
-class CTreeRootItem : public CBaseTreeItem
-{
-public:
- CTreeRootItem();
- CTreeRootItem(TCString Title, int ID, int Flags): CBaseTreeItem(Title, ID, Flags | TIF_ROOTITEM) {}
-};
-
-typedef TMyArray<CTreeItem> TreeItemArray;
-typedef TMyArray<CTreeRootItem> TreeRootItemArray;
-
-#define TREECTRL_ROOTORDEROFFS -2
-#define ROOT_INDEX_TO_ORDER(i) (TREECTRL_ROOTORDEROFFS - (i))
-#define ROOT_ORDER_TO_INDEX(i) (TREECTRL_ROOTORDEROFFS - (i))
-
-#define TREEITEMTITLE_MAXLEN 128
-#define TREEITEM_DBSTR_TITLE "Title"
-#define TREEITEM_DBSTR_PARENT "Parent"
-#define TREEITEM_DBSTR_ORDER "Order"
-#define TREEITEM_DBSTR_FLAGS "Flags"
-
-// Tree control flags
-#define TREECTRL_FLAG_IS_SINGLE_LEVEL 1 // means that the tree items can't have children, i.e. the tree is a plain list of items
-#define TREECTRL_FLAG_HAS_CHECKBOXES 2
-//#define TREECTRL_FLAG_UNORDERED 4 TODO?
-
-class COptItem_TreeCtrl : public COptItem
-{
-public:
- COptItem_TreeCtrl() {}
- COptItem_TreeCtrl(int DlgItemID, char *szDBSetting, TreeItemArray &DefValue, TreeRootItemArray RootItems, int lParam = 0, CString User_Str1_DBName = NULL, bool ReadOnly = false, int TreeFlags = 0): COptItem(DlgItemID, szDBSetting, DBVT_DWORD, lParam, ReadOnly), DefValue(DefValue), RootItems(RootItems), User_Str1_DBName(User_Str1_DBName), TreeFlags(TreeFlags)
- {
- if (TreeFlags & TREECTRL_FLAG_IS_SINGLE_LEVEL)
- {
- _ASSERT(!RootItems.GetSize()); // there can't be any root items when the tree is a plain list
- this->RootItems.AddElem(CTreeRootItem(_T(""), 0, TIF_EXPANDED)); // TODO??
- this->RootItems[0].hItem = TVI_ROOT;
- }
- }
- ~COptItem_TreeCtrl() {}
- void DBToMem(CString &sModule, CString *sDBSettingPrefix = NULL);
- void MemToDB(CString &sModule, CString *sDBSettingPrefix = NULL);
- void WndToMem(HWND hWnd);
- void MemToWnd(HWND hWnd);
- void CleanDBSettings(CString &sModule, CString *sDBSettingPrefix = NULL);
- void SetValue(int Value) {this->Value = *(TreeItemArray*)Value; COptItem::SetValue(Value);}
- void SetDefValue(int DefValue) {this->DefValue = *(TreeItemArray*)DefValue; COptItem::SetDefValue(DefValue);}
- int GetValue() {return (int)&Value;}
- int GetDefValue() {return (int)&DefValue;}
- virtual COptItem* Copy() {return new COptItem_TreeCtrl(*this);}
-
- int IDToOrder(int ID);
- int hItemToOrder(HTREEITEM hItem);
- int GenerateID();
- int GetSelectedItemID(HWND hWnd);
- void Delete(HWND hWnd, int ID);
- CTreeItem* InsertItem(HWND hWnd, CTreeItem &Item);
- void MoveItem(HWND hWnd, HTREEITEM hItem, HTREEITEM hMoveTo);
-
- TreeItemArray DefValue, Value;
- TreeRootItemArray RootItems;
- CString User_Str1_DBName;
- int TreeFlags;
-
-protected:
- void RecursiveDelete(HWND hWnd, int I);
- int RecursiveMove(int ItemOrder, int ParentID, int InsertAtOrder);
-};
-
-
-class CListItem
-{
-public:
- CListItem();
- CListItem(TCString Text): Text(Text) {}
-
- TCString Text;
-};
-
-typedef TMyArray<CListItem> ListItemArray;
-
-#define LISTITEM_DBSTR_TEXT "Text"
-
-class COptItem_ListCtrl : public COptItem
-{
-public:
- COptItem_ListCtrl() {}
- COptItem_ListCtrl(int DlgItemID, char *szDBSetting, ListItemArray &DefValue, int lParam = 0, bool ReadOnly = false): COptItem(DlgItemID, szDBSetting, DBVT_DWORD, lParam, ReadOnly), DefValue(DefValue) {}
- ~COptItem_ListCtrl() {}
- void DBToMem(CString &sModule, CString *sDBSettingPrefix = NULL);
- void MemToDB(CString &sModule, CString *sDBSettingPrefix = NULL);
- void WndToMem(HWND hWnd);
- void MemToWnd(HWND hWnd);
- void CleanDBSettings(CString &sModule, CString *sDBSettingPrefix = NULL);
- void SetValue(int Value) {this->Value = *(ListItemArray*)Value; COptItem::SetValue(Value);}
- void SetDefValue(int DefValue) {this->DefValue = *(ListItemArray*)DefValue; COptItem::SetDefValue(DefValue);}
- int GetValue() {return (int)&Value;}
- int GetDefValue() {return (int)&DefValue;}
- virtual COptItem* Copy() {return new COptItem_ListCtrl(*this);}
-
- int GetSelectedItemID(HWND hWnd); // returns -1 if there's no selection
- int SetSelectedItemID(HWND hWnd, int ID);
- void Delete(HWND hWnd, int ID);
- CListItem* InsertItem(HWND hWnd, int ID, CListItem &Item);
- void ModifyItem(HWND hWnd, int ID, CListItem &Item);
-
- ListItemArray DefValue, Value;
-};
-
-
-class COptPage
-{
-public:
- COptPage(): hWnd(NULL), sDBSettingPrefix("") {}
- COptPage(char *szModule, HWND hWnd, CString sDBSettingPrefix = ""): sModule(szModule), hWnd(hWnd), sDBSettingPrefix(sDBSettingPrefix) {}
- COptPage(const COptPage &Item);
- ~COptPage();
-
- void DBToMem();
- void MemToDB();
- void MemToPage(int OnlyEnable = 0);
- void PageToMem();
- void DBToMemToPage() {DBToMem(); MemToPage();}
- void PageToMemToDB() {PageToMem(); MemToDB();}
- void CleanDBSettings();
-
- COptItem *Find(int DlgItemID);
- int GetValue(int DlgItemID) {return Find(DlgItemID)->GetValue();}
- void SetValue(int DlgItemID, int Value) {Find(DlgItemID)->SetValue(Value);}
- int GetDBValue(int DlgItemID) {return Find(DlgItemID)->GetDBValue(sModule, &sDBSettingPrefix);}
- void SetDBValue(int DlgItemID, int Value) {Find(DlgItemID)->SetDBValue(sModule, Value, &sDBSettingPrefix);}
- int GetDBValueCopy(int DlgItemID) {return Find(DlgItemID)->GetDBValueCopy(sModule, &sDBSettingPrefix);}
- void SetDBValueCopy(int DlgItemID, int Value) {Find(DlgItemID)->SetDBValueCopy(sModule, Value, &sDBSettingPrefix);}
- int GetWndValue(int DlgItemID) {return Find(DlgItemID)->GetWndValue(hWnd);}
- void SetWndValue(int DlgItemID, int Value) {Find(DlgItemID)->SetWndValue(hWnd, Value);}
- HWND GetWnd() {return hWnd;}
- void SetWnd(HWND hWnd) {_ASSERT(!this->hWnd || !hWnd); this->hWnd = hWnd;}
- void Enable(int DlgItemID, int Enabled) {Find(DlgItemID)->Enable(Enabled);}
- bool GetModified();
- void SetModified(bool Modified);
-
- COptPage& operator = (const COptPage& Page);
-
- HWND hWnd;
- CString sModule, sDBSettingPrefix;
- TMyArray<COptItem*, COptItem*> Items;
-};
diff --git a/plugins/ClientChangeNotify/src/Misc.h b/plugins/ClientChangeNotify/src/Misc.h index b2ecf87638..29f1b72d0d 100644 --- a/plugins/ClientChangeNotify/src/Misc.h +++ b/plugins/ClientChangeNotify/src/Misc.h @@ -40,11 +40,11 @@ __inline void ShowMsg(TCHAR *FirstLine, TCHAR *SecondLine = _T(""), bool IsError __inline void ShowLog(TCString &LogFilePath)
{
- int Result = (int)ShellExecute(NULL, _T("open"), LogFilePath, NULL, NULL, SW_SHOW);
+ INT_PTR Result = (INT_PTR)ShellExecute(NULL, _T("open"), LogFilePath, NULL, NULL, SW_SHOW);
if (Result <= 32) // Error
{
TCHAR szError[64];
- mir_sntprintf(szError, lengthof(szError), TranslateT("Error #%d"), Result);
+ mir_sntprintf(szError, TranslateT("Error #%d"), Result);
ShowMsg(szError, TranslateT("Can't open log file ") + LogFilePath, true);
}
}
diff --git a/plugins/ClientChangeNotify/src/OptDlg.cpp b/plugins/ClientChangeNotify/src/OptDlg.cpp index 6d9d4f5e8f..1570f05678 100644 --- a/plugins/ClientChangeNotify/src/OptDlg.cpp +++ b/plugins/ClientChangeNotify/src/OptDlg.cpp @@ -23,39 +23,31 @@ COptPage g_PopupOptPage(MOD_NAME, NULL);
-
void EnablePopupOptDlgControls()
{
int I;
g_PopupOptPage.PageToMem();
- int UsePopups = g_PopupOptPage.GetValue(IDC_POPUPOPTDLG_POPUPNOTIFY);
- for (I = 0; I < g_PopupOptPage.Items.GetSize(); I++)
- {
- switch (g_PopupOptPage.Items[I]->GetParam())
- {
- case IDC_POPUPOPTDLG_POPUPNOTIFY:
- {
- g_PopupOptPage.Items[I]->Enable(UsePopups);
- } break;
- case IDC_POPUPOPTDLG_DEFBGCOLOUR:
- {
- g_PopupOptPage.Items[I]->Enable(UsePopups && !g_PopupOptPage.GetValue(IDC_POPUPOPTDLG_DEFBGCOLOUR));
- } break;
- case IDC_POPUPOPTDLG_DEFTEXTCOLOUR:
- {
- g_PopupOptPage.Items[I]->Enable(UsePopups && !g_PopupOptPage.GetValue(IDC_POPUPOPTDLG_DEFTEXTCOLOUR));
- } break;
+ bool UsePopups = g_PopupOptPage.GetValue(IDC_POPUPOPTDLG_POPUPNOTIFY) != 0;
+ for (I = 0; I < g_PopupOptPage.Items.GetSize(); I++) {
+ switch (g_PopupOptPage.Items[I]->GetParam()) {
+ case IDC_POPUPOPTDLG_POPUPNOTIFY:
+ g_PopupOptPage.Items[I]->Enable(UsePopups);
+ break;
+ case IDC_POPUPOPTDLG_DEFBGCOLOUR:
+ g_PopupOptPage.Items[I]->Enable(UsePopups && !g_PopupOptPage.GetValue(IDC_POPUPOPTDLG_DEFBGCOLOUR));
+ break;
+ case IDC_POPUPOPTDLG_DEFTEXTCOLOUR:
+ g_PopupOptPage.Items[I]->Enable(UsePopups && !g_PopupOptPage.GetValue(IDC_POPUPOPTDLG_DEFTEXTCOLOUR));
+ break;
}
}
- if (g_PopupOptPage.GetValue(IDC_POPUPOPTDLG_VERCHGNOTIFY))
- {
+ if (g_PopupOptPage.GetValue(IDC_POPUPOPTDLG_VERCHGNOTIFY)) {
COptItem *ShowVer = g_PopupOptPage.Find(IDC_POPUPOPTDLG_SHOWVER);
ShowVer->SetValue(1);
ShowVer->Enable(false);
ShowVer->MemToWnd(g_PopupOptPage.hWnd);
}
- if (!bFingerprintExists)
- { // disable these checkboxes if Fingerprint wasn't found
+ if (!bFingerprintExists) { // disable these checkboxes if Fingerprint wasn't found
g_PopupOptPage.Find(IDC_POPUPOPTDLG_VERCHGNOTIFY)->Enable(false);
g_PopupOptPage.Find(IDC_POPUPOPTDLG_SHOWVER)->Enable(false);
}
@@ -64,11 +56,12 @@ void EnablePopupOptDlgControls() InvalidateRect(GetDlgItem(g_PopupOptPage.GetWnd(), IDC_POPUPOPTDLG_POPUPDELAY_SPIN), NULL, false); // update spin control
}
-static struct {
+static struct
+{
TCHAR *Text;
int Action;
}
-PopupActions[] =
+PopupActions[] =
{
LPGENT("Open message window"), PCA_OPENMESSAGEWND,
LPGENT("Close popup"), PCA_CLOSEPOPUP,
@@ -93,10 +86,9 @@ INT_PTR CALLBACK PopupOptDlg(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPara HWND hLCombo = GetDlgItem(hwndDlg, IDC_POPUPOPTDLG_LCLICK_ACTION);
HWND hRCombo = GetDlgItem(hwndDlg, IDC_POPUPOPTDLG_RCLICK_ACTION);
- int I;
- for (I = 0; I < lengthof(PopupActions); I++) {
- SendMessage(hLCombo, CB_SETITEMDATA, SendMessage(hLCombo, CB_ADDSTRING, 0, (LPARAM)TranslateTS(PopupActions[I].Text)), PopupActions[I].Action);
- SendMessage(hRCombo, CB_SETITEMDATA, SendMessage(hRCombo, CB_ADDSTRING, 0, (LPARAM)TranslateTS(PopupActions[I].Text)), PopupActions[I].Action);
+ for (int i = 0; i < _countof(PopupActions); i++) {
+ SendMessage(hLCombo, CB_SETITEMDATA, SendMessage(hLCombo, CB_ADDSTRING, 0, (LPARAM)TranslateTS(PopupActions[i].Text)), PopupActions[i].Action);
+ SendMessage(hRCombo, CB_SETITEMDATA, SendMessage(hRCombo, CB_ADDSTRING, 0, (LPARAM)TranslateTS(PopupActions[i].Text)), PopupActions[i].Action);
}
g_PopupOptPage.DBToMemToPage();
EnablePopupOptDlgControls();
@@ -106,7 +98,7 @@ INT_PTR CALLBACK PopupOptDlg(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPara case WM_NOTIFY:
switch (((NMHDR*)lParam)->code) {
- case PSN_APPLY:
+ case PSN_APPLY:
g_PopupOptPage.PageToMemToDB();
RecompileRegexps(*(TCString*)g_PopupOptPage.GetValue(IDC_POPUPOPTDLG_IGNORESTRINGS));
return true;
@@ -129,11 +121,11 @@ INT_PTR CALLBACK PopupOptDlg(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPara case IDC_POPUPOPTDLG_USESTATUSNOTIFYFLAG:
SendMessage(GetParent(hwndDlg), PSM_CHANGED, (WPARAM)hwndDlg, 0);
return 0;
-
+
case IDC_POPUPOPTDLG_POPUPPREVIEW:
g_PreviewOptPage = new COptPage(g_PopupOptPage);
g_PreviewOptPage->PageToMem();
- DBCONTACTWRITESETTING cws = {0};
+ DBCONTACTWRITESETTING cws = { 0 };
cws.szModule = "ICQ";
cws.szSetting = DB_MIRVER;
db_set_s(NULL, MOD_NAME, DB_OLDMIRVER, "ICQ Lite v5");
@@ -143,7 +135,7 @@ INT_PTR CALLBACK PopupOptDlg(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPara break;
}
break;
-
+
case EN_CHANGE:
if (LOWORD(wParam) == IDC_POPUPOPTDLG_POPUPDELAY || LOWORD(wParam) == IDC_POPUPOPTDLG_IGNORESTRINGS)
if (!ChangeLock && g_PopupOptPage.GetWnd())
@@ -158,7 +150,7 @@ INT_PTR CALLBACK PopupOptDlg(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPara break;
}
break;
-
+
case WM_DESTROY:
g_PopupOptPage.SetWnd(NULL);
return 0;
diff --git a/plugins/ClientChangeNotify/src/Options.cpp b/plugins/ClientChangeNotify/src/Options.cpp new file mode 100644 index 0000000000..c6209078f9 --- /dev/null +++ b/plugins/ClientChangeNotify/src/Options.cpp @@ -0,0 +1,816 @@ +/*
+ Options.cpp
+ Copyright (c) 2005-2008 Chervov Dmitry
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#include "stdafx.h"
+#include "Options.h"
+
+static CString sEmptyString("");
+
+COptPage::COptPage(const COptPage &Item)
+{
+ *this = Item;
+}
+
+COptPage::~COptPage()
+{
+ for (int i = 0; i < Items.GetSize(); i++)
+ delete Items[i];
+
+ Items.RemoveAll();
+}
+
+void COptPage::MemToPage(int OnlyEnable)
+{
+ _ASSERT(hWnd);
+ for (int i = 0; i < Items.GetSize(); i++) {
+ if (OnlyEnable)
+ Items[i]->COptItem::MemToWnd(hWnd);
+ else
+ Items[i]->MemToWnd(hWnd);
+ }
+}
+
+void COptPage::PageToMem()
+{
+ _ASSERT(hWnd);
+ for (int i = 0; i < Items.GetSize(); i++)
+ Items[i]->WndToMem(hWnd);
+}
+
+void COptPage::DBToMem()
+{
+ _ASSERT(sModule != "");
+ for (int i = 0; i < Items.GetSize(); i++)
+ Items[i]->DBToMem(sModule, &sDBSettingPrefix);
+}
+
+void COptPage::MemToDB()
+{
+ _ASSERT(sModule != "");
+ for (int i = 0; i < Items.GetSize(); i++)
+ Items[i]->MemToDB(sModule, &sDBSettingPrefix);
+}
+
+void COptPage::CleanDBSettings()
+{
+ _ASSERT(sModule != "");
+ for (int i = 0; i < Items.GetSize(); i++)
+ Items[i]->CleanDBSettings(sModule, &sDBSettingPrefix);
+}
+
+bool COptPage::GetModified()
+{
+ _ASSERT(sModule != "");
+ for (int i = 0; i < Items.GetSize(); i++)
+ if (Items[i]->GetModified())
+ return true;
+
+ return false;
+}
+
+void COptPage::SetModified(bool m_bModified)
+{
+ _ASSERT(sModule != "");
+ for (int i = 0; i < Items.GetSize(); i++)
+ Items[i]->SetModified(m_bModified);
+}
+
+COptItem *COptPage::Find(int m_dlgItemID)
+{
+ for (int i = 0; i < Items.GetSize(); i++)
+ if (Items[i]->GetID() == m_dlgItemID)
+ return Items[i];
+
+ _ASSERT(0);
+ return 0;
+}
+
+COptPage& COptPage::operator = (const COptPage& Page)
+{
+ hWnd = Page.hWnd;
+ sModule = Page.sModule;
+ sDBSettingPrefix = Page.sDBSettingPrefix;
+ Items.RemoveAll();
+ for (int i = 0; i < Page.Items.GetSize(); i++)
+ Items.AddElem(Page.Items[i]->Copy());
+
+ return *this;
+}
+
+
+int COptItem::GetIntDBVal(const CString &sModule, int bSigned, CString*)
+{ // default procedure for reading value from DB; used only for integral types
+ if (sDBSetting != NULL) {
+ _ASSERT(nValueSize == DBVT_BYTE || nValueSize == DBVT_WORD || nValueSize == DBVT_DWORD);
+ DBVARIANT dbv;
+ if (db_get(NULL, sModule, sDBSetting, &dbv))
+ return (int)GetDefValue();
+
+ return (nValueSize == DBVT_BYTE) ? (bSigned ? (signed char)dbv.bVal : (unsigned char)dbv.bVal) : ((nValueSize == DBVT_WORD) ? (bSigned ? (signed short)dbv.wVal : (unsigned short)dbv.wVal) : dbv.dVal);
+ }
+ return (int)GetDefValue();
+}
+
+void COptItem::SetIntDBVal(const CString &sModule, int m_value, CString*)
+{ // default procedure for writing value to the DB; used only for integral types
+ if (sDBSetting != NULL && !m_bReadOnly) {
+ _ASSERT(nValueSize == DBVT_BYTE || nValueSize == DBVT_WORD || nValueSize == DBVT_DWORD);
+
+ DBVARIANT dbv;
+ dbv.type = nValueSize;
+ dbv.dVal = m_value;
+ db_set(NULL, sModule, sDBSetting, &dbv);
+ }
+}
+
+TCString COptItem::GetStrDBVal(const CString &sModule, CString *sDBSettingPrefix)
+{
+ if (sDBSetting != NULL) {
+ _ASSERT(GetDefValue());
+ return db_get_s(NULL, sModule, sDBSettingPrefix ? (*sDBSettingPrefix + sDBSetting) : sDBSetting, *(TCString*)GetDefValue());
+ }
+ return *(TCString*)GetDefValue();
+}
+
+void COptItem::SetStrDBVal(const CString &sModule, TCString &Str, CString *sDBSettingPrefix)
+{
+ if (sDBSetting != NULL && !m_bReadOnly) {
+ db_set_ts(NULL, sModule, sDBSettingPrefix ? (*sDBSettingPrefix + sDBSetting) : sDBSetting, Str);
+ }
+}
+
+void COptItem_Checkbox::DBToMem(const CString &sModule, CString *sDBSettingPrefix)
+{
+ if (m_valueMask)
+ m_value = (GetIntDBVal(sModule, false, sDBSettingPrefix) & m_valueMask) ? BST_CHECKED : BST_UNCHECKED;
+ else
+ m_value = GetIntDBVal(sModule, false, sDBSettingPrefix);
+
+ COptItem::DBToMem(sModule, sDBSettingPrefix);
+}
+
+void COptItem_Checkbox::MemToDB(const CString &sModule, CString *sDBSettingPrefix)
+{
+ if (m_valueMask) {
+ if (m_value == BST_CHECKED)
+ SetIntDBVal(sModule, GetIntDBVal(sModule, false, sDBSettingPrefix) | m_valueMask, sDBSettingPrefix);
+ else
+ SetIntDBVal(sModule, GetIntDBVal(sModule, false, sDBSettingPrefix) & ~m_valueMask, sDBSettingPrefix);
+ }
+ else SetIntDBVal(sModule, m_value, sDBSettingPrefix);
+
+ COptItem::MemToDB(sModule, sDBSettingPrefix);
+}
+
+void COptItem_Checkbox::WndToMem(HWND hWnd)
+{
+ m_value = IsDlgButtonChecked(hWnd, m_dlgItemID);
+ // tri-state checkboxes in combination with m_valueMask != 0 are not supported ;)
+ _ASSERT(!m_valueMask || m_value != BST_INDETERMINATE);
+ COptItem::WndToMem(hWnd);
+}
+
+void COptItem_Checkbox::MemToWnd(HWND hWnd)
+{
+ CheckDlgButton(hWnd, m_dlgItemID, m_value ? BST_CHECKED : BST_UNCHECKED);
+ COptItem::MemToWnd(hWnd);
+}
+
+void COptItem_BitDBSetting::DBToMem(const CString &sModule, CString *sDBSettingPrefix)
+{
+ if (m_valueMask)
+ m_value = (GetIntDBVal(sModule, false, sDBSettingPrefix) & m_valueMask) != 0;
+ else
+ m_value = GetIntDBVal(sModule, false, sDBSettingPrefix);
+
+ COptItem::DBToMem(sModule, sDBSettingPrefix);
+}
+
+void COptItem_BitDBSetting::MemToDB(const CString &sModule, CString *sDBSettingPrefix)
+{
+ if (m_valueMask) {
+ if (m_value)
+ SetIntDBVal(sModule, GetIntDBVal(sModule, false, sDBSettingPrefix) | m_valueMask, sDBSettingPrefix);
+ else
+ SetIntDBVal(sModule, GetIntDBVal(sModule, false, sDBSettingPrefix) & ~m_valueMask, sDBSettingPrefix);
+ }
+ else SetIntDBVal(sModule, m_value, sDBSettingPrefix);
+
+ COptItem::MemToDB(sModule, sDBSettingPrefix);
+}
+
+
+// ================================================ COptItem_TreeCtrl ================================================
+
+int COptItem_TreeCtrl::IDToOrder(int ID)
+{
+ for (int i = 0; i < RootItems.GetSize(); i++)
+ if (RootItems[i].ID == ID)
+ return ROOT_INDEX_TO_ORDER(i);
+
+ for (int i = 0; i < m_value.GetSize(); i++)
+ if (m_value[i].ID == ID)
+ return i;
+
+ return -1;
+}
+
+int COptItem_TreeCtrl::hItemToOrder(HTREEITEM hItem)
+{
+ for (int i = 0; i < RootItems.GetSize(); i++)
+ if (RootItems[i].hItem == hItem)
+ return ROOT_INDEX_TO_ORDER(i);
+
+ for (int i = 0; i < m_value.GetSize(); i++)
+ if (m_value[i].hItem == hItem)
+ return i;
+
+ return -1;
+}
+
+int COptItem_TreeCtrl::GenerateID()
+{
+ int ID = 0;
+ while (IDToOrder(ID) != -1)
+ ID++;
+
+ return ID;
+}
+
+struct sTreeReadEnumData
+{
+ sTreeReadEnumData(COptItem_TreeCtrl *_p1, const CString &_p2, const CString &_p3) :
+ TreeCtrl(_p1),
+ sModule(_p2),
+ sDBSettingPrefix(_p3)
+ {}
+
+ COptItem_TreeCtrl *TreeCtrl;
+ const CString &sModule, &sDBSettingPrefix;
+};
+
+int TreeReadEnum(const char *szSetting, LPARAM lParam)
+{
+ sTreeReadEnumData *pData = (sTreeReadEnumData*)lParam;
+ int Len = pData->TreeCtrl->sDBSetting.GetLen() + _countof(TREEITEM_DBSTR_TITLE) - 1;
+ if (!strncmp(szSetting, pData->TreeCtrl->sDBSetting + TREEITEM_DBSTR_TITLE, Len) && isdigit(szSetting[Len])) {
+ int ID = atol(szSetting + Len);
+ short ParentID = (pData->TreeCtrl->TreeFlags & TREECTRL_FLAG_IS_SINGLE_LEVEL) ? 0 : db_get_w(NULL, pData->sModule,
+ pData->sDBSettingPrefix + pData->TreeCtrl->sDBSetting + TREEITEM_DBSTR_PARENT + (szSetting + Len), -1);
+ short Order = db_get_w(NULL, pData->sModule,
+ pData->sDBSettingPrefix + pData->TreeCtrl->sDBSetting + TREEITEM_DBSTR_ORDER + (szSetting + Len), -1);
+ char Flags = (pData->TreeCtrl->TreeFlags & TREECTRL_FLAG_IS_SINGLE_LEVEL && !(pData->TreeCtrl->TreeFlags & TREECTRL_FLAG_HAS_CHECKBOXES)) ? 0 : db_get_b(NULL, pData->sModule,
+ pData->sDBSettingPrefix + pData->TreeCtrl->sDBSetting + TREEITEM_DBSTR_FLAGS + (szSetting + Len), 0);
+ if (ParentID >= 0 && Order >= 0) {
+ CTreeItem &pItem = pData->TreeCtrl->m_value.SetAtGrow(Order);
+ pItem.ID = ID;
+ pItem.ParentID = ParentID;
+ pItem.Flags = Flags;
+ pItem.hItem = NULL;
+ pItem.Title = db_get_s(NULL, pData->sModule, *pData->sDBSettingPrefix + szSetting, _T(""));
+ pItem.User_Str1 = (pData->TreeCtrl->User_Str1_DBName == NULL) ? NULL :
+ db_get_s(NULL, pData->sModule,
+ *pData->sDBSettingPrefix + pData->TreeCtrl->sDBSetting + pData->TreeCtrl->User_Str1_DBName + (szSetting + Len), (TCHAR*)NULL);
+ }
+ }
+ return 0;
+}
+
+void COptItem_TreeCtrl::DBToMem(const CString &sModule, CString *sDBSettingPrefix)
+{
+ if (!sDBSettingPrefix)
+ sDBSettingPrefix = &sEmptyString;
+
+ m_value.RemoveAll();
+ sTreeReadEnumData pData(this, sModule, *sDBSettingPrefix);
+
+ DBCONTACTENUMSETTINGS dbEnum;
+ dbEnum.lParam = (LPARAM)&pData;
+ dbEnum.ofsSettings = 0;
+ dbEnum.pfnEnumProc = TreeReadEnum;
+ dbEnum.szModule = sModule;
+ CallService(MS_DB_CONTACT_ENUMSETTINGS, NULL, (LPARAM)&dbEnum);
+ if (!m_value.GetSize()) {
+ m_value = m_defValue;
+ }
+ else {
+ for (int i = 0; i < m_value.GetSize(); i++) {
+ if (m_value[i].Title == NULL) {
+ m_value.RemoveElem(i);
+ i--;
+ }
+ }
+ }
+ COptItem::DBToMem(sModule, sDBSettingPrefix);
+}
+
+void COptItem_TreeCtrl::MemToDB(const CString &sModule, CString *sDBSettingPrefix)
+{
+ if (!m_bReadOnly && m_bModified) {
+ if (!sDBSettingPrefix)
+ sDBSettingPrefix = &sEmptyString;
+
+ CleanDBSettings(sModule, sDBSettingPrefix);
+ for (int i = 0; i < m_value.GetSize(); i++) {
+ CString StrID;
+ _itoa(m_value[i].ID, StrID.GetBuffer(64), 10);
+ StrID.ReleaseBuffer();
+ db_set_ts(NULL, sModule, *sDBSettingPrefix + sDBSetting + TREEITEM_DBSTR_TITLE + StrID, m_value[i].Title);
+ if (!(TreeFlags & TREECTRL_FLAG_IS_SINGLE_LEVEL))
+ db_set_w(NULL, sModule, *sDBSettingPrefix + sDBSetting + TREEITEM_DBSTR_PARENT + StrID, m_value[i].ParentID);
+
+ db_set_w(NULL, sModule, *sDBSettingPrefix + sDBSetting + TREEITEM_DBSTR_ORDER + StrID, i);
+ if (!(TreeFlags & TREECTRL_FLAG_IS_SINGLE_LEVEL) || TreeFlags & TREECTRL_FLAG_HAS_CHECKBOXES)
+ db_set_b(NULL, sModule, *sDBSettingPrefix + sDBSetting + TREEITEM_DBSTR_FLAGS + StrID, m_value[i].Flags);
+
+ if (User_Str1_DBName != NULL && m_value[i].User_Str1 != NULL)
+ db_set_ts(NULL, sModule, *sDBSettingPrefix + sDBSetting + User_Str1_DBName + StrID, m_value[i].User_Str1);
+ }
+ COptItem::MemToDB(sModule, sDBSettingPrefix);
+ }
+}
+
+void COptItem_TreeCtrl::WndToMem(HWND hWnd)
+{ // only need to gather info of items state (expanded/collapsed, checked/unchecked)
+ HWND hTreeView = GetDlgItem(hWnd, m_dlgItemID);
+ for (int i = 0; i < m_value.GetSize(); i++) {
+ DWORD State = TreeView_GetItemState(hTreeView, m_value[i].hItem, TVIS_EXPANDED | TVIS_STATEIMAGEMASK);
+ int OldFlags = m_value[i].Flags;
+ if (State & TVIS_EXPANDED)
+ m_value[i].Flags |= TIF_EXPANDED;
+ else
+ m_value[i].Flags &= ~TIF_EXPANDED;
+
+ if (TreeFlags & TREECTRL_FLAG_HAS_CHECKBOXES && (State >> 12) - 1)
+ m_value[i].Flags |= TIF_ENABLED;
+ else
+ m_value[i].Flags &= ~TIF_ENABLED;
+
+ if (m_value[i].Flags != OldFlags)
+ m_bModified = true;
+ }
+ COptItem::WndToMem(hWnd);
+}
+
+void COptItem_TreeCtrl::MemToWnd(HWND hWnd)
+{
+ HWND hTreeView = GetDlgItem(hWnd, m_dlgItemID);
+ if (TreeFlags & TREECTRL_FLAG_HAS_CHECKBOXES) { // have to set this in run-time as it's specified in MSDN
+ LONG_PTR Style = GetWindowLongPtr(hTreeView, GWL_STYLE);
+ SetWindowLongPtr(hTreeView, GWL_STYLE, Style & ~TVS_CHECKBOXES);
+ SetWindowLongPtr(hTreeView, GWL_STYLE, Style | TVS_CHECKBOXES);
+ }
+
+ TVINSERTSTRUCT tvIn = { 0 };
+ int ScrollPos = GetScrollPos(hTreeView, SB_VERT);
+ int SelectOrder = IDToOrder(GetSelectedItemID(hWnd));
+ SendMessage(hTreeView, WM_SETREDRAW, false, 0);
+ TreeView_DeleteAllItems(hTreeView);
+ _ASSERT(RootItems.GetSize());
+
+ if (!(TreeFlags & TREECTRL_FLAG_IS_SINGLE_LEVEL)) {
+ for (int i = 0; i < RootItems.GetSize(); i++) {
+ tvIn.item.mask = TVIF_TEXT | TVIF_STATE | TVIF_PARAM;
+ RootItems[i].Flags |= TIF_GROUP;
+ tvIn.item.state = tvIn.item.stateMask = TVIS_BOLD | ((RootItems[i].Flags & TIF_EXPANDED) ? TVIS_EXPANDED : 0);
+ tvIn.item.pszText = RootItems[i].Title;
+ tvIn.hParent = TVI_ROOT;
+ tvIn.hInsertAfter = TVI_LAST;
+ tvIn.item.lParam = RootItems[i].ID;
+ RootItems[i].hItem = TreeView_InsertItem(hTreeView, &tvIn);
+ }
+ }
+ for (int i = 0; i < m_value.GetSize(); i++)
+ m_value[i].hItem = RootItems[0].hItem; // put an item to first group in case of some strange error
+
+ for (int i = 0; i < m_value.GetSize(); i++) {
+ tvIn.item.mask = TVIF_TEXT | TVIF_STATE | TVIF_PARAM;
+ tvIn.item.state = tvIn.item.stateMask = (m_value[i].Flags & TIF_GROUP) ? (TVIS_BOLD | ((m_value[i].Flags & TIF_EXPANDED) ? TVIS_EXPANDED : 0)) : 0;
+ if (TreeFlags & TREECTRL_FLAG_HAS_CHECKBOXES) {
+ tvIn.item.stateMask |= TVIS_STATEIMAGEMASK;
+ tvIn.item.state |= INDEXTOSTATEIMAGEMASK((m_value[i].Flags & TIF_ENABLED) ? 2 : 1);
+ }
+ tvIn.item.pszText = m_value[i].Title;
+ int Order = IDToOrder(m_value[i].ParentID);
+ if (Order != -1) {
+ tvIn.hParent = (Order <= TREECTRL_ROOTORDEROFFS) ? RootItems[ROOT_ORDER_TO_INDEX(Order)].hItem : m_value[Order].hItem;
+ tvIn.hInsertAfter = TVI_LAST;
+ tvIn.item.lParam = m_value[i].ID;
+ m_value[i].hItem = TreeView_InsertItem(hTreeView, &tvIn);
+ }
+ else { // found an orphan item; probably it's better just to delete it
+ m_value.RemoveElem(i);
+ i--;
+ }
+ }
+ TreeView_SelectItem(hTreeView, (SelectOrder >= 0) ? m_value[SelectOrder].hItem : ((SelectOrder <= TREECTRL_ROOTORDEROFFS) ? RootItems[ROOT_ORDER_TO_INDEX(SelectOrder)].hItem : NULL));
+ SendMessage(hTreeView, WM_SETREDRAW, true, 0);
+ SCROLLBARINFO sbi;
+ sbi.cbSize = sizeof(sbi);
+ GetScrollBarInfo(hTreeView, OBJID_VSCROLL, &sbi);
+ if (!(sbi.rgstate[0] & STATE_SYSTEM_INVISIBLE)) {
+ int MinPos, MaxPos;
+ GetScrollRange(hTreeView, SB_VERT, &MinPos, &MaxPos);
+ if (ScrollPos < MinPos) {
+ ScrollPos = MinPos;
+ }
+ else if (ScrollPos > MaxPos) {
+ ScrollPos = MaxPos;
+ }
+ SetScrollPos(hTreeView, SB_VERT, ScrollPos, true);
+ }
+ COptItem::MemToWnd(hWnd);
+}
+
+
+typedef struct
+{
+ TMyArray<CString> TreeSettings;
+ COptItem_TreeCtrl *TreeCtrl;
+ CString *sDBSettingPrefix;
+} sTreeDeleteEnumData;
+
+int TreeDeleteEnum(const char *szSetting, LPARAM lParam)
+{
+ sTreeDeleteEnumData *TreeDeleteEnumData = (sTreeDeleteEnumData*)lParam;
+ CString CurSetting = *TreeDeleteEnumData->sDBSettingPrefix + TreeDeleteEnumData->TreeCtrl->sDBSetting + TREEITEM_DBSTR_TITLE;
+ if (!strncmp(szSetting, CurSetting, CurSetting.GetLen()))
+ TreeDeleteEnumData->TreeSettings.AddElem(szSetting);
+
+ CurSetting = *TreeDeleteEnumData->sDBSettingPrefix + TreeDeleteEnumData->TreeCtrl->sDBSetting + TREEITEM_DBSTR_PARENT;
+ if (!strncmp(szSetting, CurSetting, CurSetting.GetLen()))
+ TreeDeleteEnumData->TreeSettings.AddElem(szSetting);
+
+ CurSetting = *TreeDeleteEnumData->sDBSettingPrefix + TreeDeleteEnumData->TreeCtrl->sDBSetting + TREEITEM_DBSTR_ORDER;
+ if (!strncmp(szSetting, CurSetting, CurSetting.GetLen()))
+ TreeDeleteEnumData->TreeSettings.AddElem(szSetting);
+
+ CurSetting = *TreeDeleteEnumData->sDBSettingPrefix + TreeDeleteEnumData->TreeCtrl->sDBSetting + TREEITEM_DBSTR_FLAGS;
+ if (!strncmp(szSetting, CurSetting, CurSetting.GetLen()))
+ TreeDeleteEnumData->TreeSettings.AddElem(szSetting);
+
+ if (TreeDeleteEnumData->TreeCtrl->User_Str1_DBName != NULL) {
+ CurSetting = *TreeDeleteEnumData->sDBSettingPrefix + TreeDeleteEnumData->TreeCtrl->sDBSetting + TreeDeleteEnumData->TreeCtrl->User_Str1_DBName;
+ if (!strncmp(szSetting, CurSetting, CurSetting.GetLen()))
+ TreeDeleteEnumData->TreeSettings.AddElem(szSetting);
+ }
+ return 0;
+}
+
+void COptItem_TreeCtrl::CleanDBSettings(const CString &sModule, CString *sDBSettingPrefix)
+{
+ if (!sDBSettingPrefix)
+ sDBSettingPrefix = &sEmptyString;
+
+ sTreeDeleteEnumData TreeDeleteEnumData;
+ TreeDeleteEnumData.TreeCtrl = this;
+ TreeDeleteEnumData.sDBSettingPrefix = sDBSettingPrefix;
+ DBCONTACTENUMSETTINGS dbEnum;
+ dbEnum.lParam = (LPARAM)&TreeDeleteEnumData;
+ dbEnum.ofsSettings = 0;
+ dbEnum.pfnEnumProc = TreeDeleteEnum;
+ dbEnum.szModule = sModule;
+ CallService(MS_DB_CONTACT_ENUMSETTINGS, NULL, (LPARAM)&dbEnum);
+
+ for (int i = 0; i < TreeDeleteEnumData.TreeSettings.GetSize(); i++)
+ db_unset(NULL, sModule, TreeDeleteEnumData.TreeSettings[i]);
+}
+
+int COptItem_TreeCtrl::GetSelectedItemID(HWND hWnd)
+{
+ HWND hTreeView = GetDlgItem(hWnd, m_dlgItemID);
+ TVITEM tvi = { 0 };
+ tvi.hItem = TreeView_GetSelection(hTreeView);
+ if (!tvi.hItem)
+ return -1;
+
+ tvi.mask = TVIF_HANDLE | TVIF_PARAM;
+ TreeView_GetItem(hTreeView, &tvi);
+ return tvi.lParam;
+}
+
+void COptItem_TreeCtrl::Delete(HWND hWnd, int ID)
+{
+ int SelectedOrder = IDToOrder(ID);
+ _ASSERT(SelectedOrder >= 0);
+ RecursiveDelete(hWnd, SelectedOrder);
+ m_bModified = true;
+}
+
+void COptItem_TreeCtrl::RecursiveDelete(HWND hWnd, int i)
+{
+ if (m_value[i].Flags & TIF_GROUP)
+ for (int j = i + 1; j < m_value.GetSize(); j++)
+ if (m_value[j].ParentID == m_value[i].ID)
+ RecursiveDelete(hWnd, j--);
+
+ HWND hTreeView = GetDlgItem(hWnd, m_dlgItemID);
+ TreeView_DeleteItem(hTreeView, m_value[i].hItem);
+ m_value.RemoveElem(i);
+}
+
+CTreeItem* COptItem_TreeCtrl::InsertItem(HWND hWnd, CTreeItem &Item)
+// Item's ID and ParentID are not used (the new item position is determined by current selection in the tree)
+// returns a pointer to the newly inserted item info
+{
+ _ASSERT(!(TreeFlags & TREECTRL_FLAG_IS_SINGLE_LEVEL) || !(Item.Flags & TIF_GROUP));
+ HWND hTreeView = GetDlgItem(hWnd, m_dlgItemID);
+ TVITEM tvi;
+ int SelOrder = -1;
+ Item.ParentID = RootItems[0].ID;
+ TVINSERTSTRUCT tvIn = { 0 };
+ tvIn.hParent = RootItems[0].hItem;
+ tvIn.hInsertAfter = TVI_FIRST;
+ if (tvi.hItem = TreeView_GetSelection(hTreeView)) {
+ tvi.mask = TVIF_HANDLE | TVIF_PARAM;
+ TreeView_GetItem(hTreeView, &tvi);
+ SelOrder = IDToOrder(tvi.lParam);
+ if (SelOrder <= TREECTRL_ROOTORDEROFFS) {
+ Item.ParentID = RootItems[ROOT_ORDER_TO_INDEX(SelOrder)].ID;
+ tvIn.hParent = RootItems[ROOT_ORDER_TO_INDEX(SelOrder)].hItem;
+ SelOrder = -1;
+ }
+ else {
+ if (m_value[SelOrder].Flags & TIF_GROUP) {
+ Item.ParentID = m_value[SelOrder].ID;
+ tvIn.hParent = m_value[SelOrder].hItem;
+ }
+ else {
+ Item.ParentID = m_value[SelOrder].ParentID;
+ int Order = IDToOrder(m_value[SelOrder].ParentID);
+ tvIn.hParent = (Order <= TREECTRL_ROOTORDEROFFS) ? RootItems[ROOT_ORDER_TO_INDEX(Order)].hItem : m_value[Order].hItem;
+ tvIn.hInsertAfter = m_value[SelOrder].hItem;
+ }
+ }
+ }
+ tvIn.item.mask = TVIF_TEXT | TVIF_STATE | TVIF_PARAM;
+ tvIn.item.state = tvIn.item.stateMask = (Item.Flags & TIF_GROUP) ? (TVIS_BOLD | ((Item.Flags & TIF_EXPANDED) ? TVIS_EXPANDED : 0)) : 0;
+ if (TreeFlags & TREECTRL_FLAG_HAS_CHECKBOXES) {
+ tvIn.item.stateMask |= TVIS_STATEIMAGEMASK;
+ tvIn.item.state |= INDEXTOSTATEIMAGEMASK((Item.Flags & TIF_ENABLED) ? 2 : 1);
+ }
+ tvIn.item.pszText = Item.Title;
+ tvIn.item.lParam = Item.ID = GenerateID();
+ m_value.InsertElem(Item, SelOrder + 1);
+ m_value[SelOrder + 1].hItem = TreeView_InsertItem(hTreeView, &tvIn);
+ TreeView_SelectItem(hTreeView, m_value[SelOrder + 1].hItem);
+ m_bModified = true;
+ return &m_value[SelOrder + 1];
+}
+
+int COptItem_TreeCtrl::RecursiveMove(int ItemOrder, int ParentID, int InsertAtOrder)
+// ItemOrder must be a movable item (i.e. ItemOrder >= 0)
+// InsertAtOrder must be >= 0 too.
+{
+ int ItemsMoved = 1;
+ m_value.MoveElem(ItemOrder, InsertAtOrder);
+ m_value[InsertAtOrder].ParentID = ParentID;
+ if (m_value[InsertAtOrder].Flags & TIF_GROUP) { // need to ensure that no items were left before their group by an order.
+ int GroupID = m_value[InsertAtOrder].ID;
+ for (int i = ItemOrder; i < InsertAtOrder; i++) { // if ItemOrder > InsertAtOrder then there is simply nothing to do
+ if (m_value[i].ParentID == GroupID) {
+ int CurrentItemsMoved = RecursiveMove(i, GroupID, InsertAtOrder);
+ ItemsMoved += CurrentItemsMoved;
+ InsertAtOrder -= CurrentItemsMoved;
+ i--;
+ }
+ }
+ }
+ return ItemsMoved;
+}
+
+void COptItem_TreeCtrl::MoveItem(HWND hWnd, HTREEITEM hItem, HTREEITEM hMoveTo)
+{ // hMoveTo can be NULL and it means that we must move hItem to the beginning of the list
+ _ASSERT(hItem && (hMoveTo || TreeFlags & TREECTRL_FLAG_IS_SINGLE_LEVEL));
+ if (hItem == hMoveTo)
+ return;
+
+ HWND hTreeView = GetDlgItem(hWnd, m_dlgItemID);
+ TVITEM tvi;
+ tvi.mask = TVIF_HANDLE | TVIF_PARAM;
+ tvi.hItem = hItem;
+ TreeView_GetItem(hTreeView, &tvi);
+ int ItemOrder = IDToOrder(tvi.lParam);
+ _ASSERT(ItemOrder != -1);
+ int MoveToOrder;
+ if (hMoveTo) {
+ tvi.hItem = hMoveTo;
+ TreeView_GetItem(hTreeView, &tvi);
+ MoveToOrder = IDToOrder(tvi.lParam);
+ _ASSERT(MoveToOrder != -1);
+ }
+ else MoveToOrder = -1;
+
+ if (ItemOrder <= TREECTRL_ROOTORDEROFFS)
+ return; // can't move root items
+
+ if (m_value[ItemOrder].Flags & TIF_GROUP) { // need to check for a case when trying to move a group to its own subgroup.
+ int Order = MoveToOrder;
+ while (Order >= 0) {
+ Order = IDToOrder(m_value[Order].ParentID);
+ if (Order == ItemOrder)
+ return;
+ }
+ }
+ // well, everything is ok, we really can move that item.
+ WndToMem(hWnd); // save groups state (expanded/collapsed)
+ if (MoveToOrder != -1 && ((MoveToOrder <= TREECTRL_ROOTORDEROFFS) ? RootItems[ROOT_ORDER_TO_INDEX(MoveToOrder)].Flags : m_value[MoveToOrder].Flags) & TIF_GROUP) // if the destination is a group, then move the item to that group
+ RecursiveMove(ItemOrder, (MoveToOrder <= TREECTRL_ROOTORDEROFFS) ? RootItems[ROOT_ORDER_TO_INDEX(MoveToOrder)].ID : m_value[MoveToOrder].ID, (MoveToOrder >= 0) ? ((ItemOrder < MoveToOrder) ? MoveToOrder : (MoveToOrder + 1)) : 0);
+ else // else place the item after the destination item
+ RecursiveMove(ItemOrder, (MoveToOrder == -1) ? 0 : m_value[MoveToOrder].ParentID, (ItemOrder < MoveToOrder) ? MoveToOrder : (MoveToOrder + 1)); // when TREECTRL_FLAG_IS_SINGLE_LEVEL, we always have a root item with ID = 0.
+
+ MemToWnd(hWnd); // update the tree
+ m_bModified = true;
+}
+
+
+// ================================================ COptItem_ListCtrl ================================================
+
+struct sListReadEnumData
+{
+ sListReadEnumData(COptItem_ListCtrl *p1, const CString &p2, const CString &p3) :
+ ListCtrl(p1),
+ sModule(p2),
+ sDBSettingPrefix(p3)
+ {}
+
+ COptItem_ListCtrl *ListCtrl;
+ const CString &sModule, &sDBSettingPrefix;
+};
+
+int ListReadEnum(const char *szSetting, LPARAM lParam)
+{
+ sListReadEnumData *pData = (sListReadEnumData*)lParam;
+ int Len = pData->sDBSettingPrefix.GetLen() + pData->ListCtrl->sDBSetting.GetLen() + _countof(LISTITEM_DBSTR_TEXT) - 1;
+ if (!strncmp(szSetting, pData->sDBSettingPrefix + pData->ListCtrl->sDBSetting + LISTITEM_DBSTR_TEXT, Len) && isdigit(szSetting[Len])) {
+ int ID = atol(szSetting + Len);
+ pData->ListCtrl->m_value.SetAtGrow(ID).Text = db_get_s(NULL, pData->sModule, *pData->sDBSettingPrefix + szSetting, _T(""));
+ }
+ return 0;
+}
+
+void COptItem_ListCtrl::DBToMem(const CString &sModule, CString *sDBSettingPrefix)
+{
+ if (!sDBSettingPrefix)
+ sDBSettingPrefix = &sEmptyString;
+
+ m_value.RemoveAll();
+ sListReadEnumData pData(this, sModule, *sDBSettingPrefix);
+ DBCONTACTENUMSETTINGS dbEnum;
+ dbEnum.lParam = (LPARAM)&pData;
+ dbEnum.ofsSettings = 0;
+ dbEnum.pfnEnumProc = ListReadEnum;
+ dbEnum.szModule = sModule;
+ CallService(MS_DB_CONTACT_ENUMSETTINGS, NULL, (LPARAM)&dbEnum);
+ if (!m_value.GetSize())
+ m_value = m_defValue;
+ else {
+ for (int i = 0; i < m_value.GetSize(); i++) {
+ if (m_value[i].Text == NULL) {
+ m_value.RemoveElem(i);
+ i--;
+ }
+ }
+ }
+ COptItem::DBToMem(sModule, sDBSettingPrefix);
+}
+
+void COptItem_ListCtrl::MemToDB(const CString &sModule, CString *sDBSettingPrefix)
+{
+ if (!m_bReadOnly && m_bModified) {
+ if (!sDBSettingPrefix)
+ sDBSettingPrefix = &sEmptyString;
+
+ CleanDBSettings(sModule, sDBSettingPrefix);
+
+ for (int i = 0; i < m_value.GetSize(); i++) {
+ CString StrID;
+ _itoa(i, StrID.GetBuffer(64), 10);
+ StrID.ReleaseBuffer();
+ db_set_ts(NULL, sModule, *sDBSettingPrefix + sDBSetting + LISTITEM_DBSTR_TEXT + StrID, m_value[i].Text);
+ }
+ COptItem::MemToDB(sModule, sDBSettingPrefix);
+ }
+}
+
+void COptItem_ListCtrl::WndToMem(HWND hWnd)
+{
+ // nothing to do
+ COptItem::WndToMem(hWnd);
+}
+
+void COptItem_ListCtrl::MemToWnd(HWND hWnd)
+{
+ HWND hListView = GetDlgItem(hWnd, m_dlgItemID);
+ SendMessage(hListView, WM_SETREDRAW, false, 0);
+ SendMessage(hListView, LB_RESETCONTENT, 0, 0);
+
+ for (int i = 0; i < m_value.GetSize(); i++)
+ SendMessage(hListView, LB_INSERTSTRING, -1, (LPARAM)(TCHAR*)m_value[i].Text);
+
+ SendMessage(hListView, WM_SETREDRAW, true, 0);
+ COptItem::MemToWnd(hWnd);
+}
+
+typedef struct
+{
+ TMyArray<CString> ListSettings;
+ COptItem_ListCtrl *ListCtrl;
+ CString *sDBSettingPrefix;
+} sListDeleteEnumData;
+
+int ListDeleteEnum(const char *szSetting, LPARAM lParam)
+{
+ sListDeleteEnumData *ListDeleteEnumData = (sListDeleteEnumData*)lParam;
+ CString CurSetting = *ListDeleteEnumData->sDBSettingPrefix + ListDeleteEnumData->ListCtrl->sDBSetting + LISTITEM_DBSTR_TEXT;
+ if (!strncmp(szSetting, CurSetting, CurSetting.GetLen()))
+ ListDeleteEnumData->ListSettings.AddElem(szSetting);
+ return 0;
+}
+
+void COptItem_ListCtrl::CleanDBSettings(const CString &sModule, CString *sDBSettingPrefix)
+{
+ if (!sDBSettingPrefix)
+ sDBSettingPrefix = &sEmptyString;
+
+ sListDeleteEnumData ListDeleteEnumData;
+ ListDeleteEnumData.ListCtrl = this;
+ ListDeleteEnumData.sDBSettingPrefix = sDBSettingPrefix;
+ DBCONTACTENUMSETTINGS dbEnum;
+ dbEnum.lParam = (LPARAM)&ListDeleteEnumData;
+ dbEnum.ofsSettings = 0;
+ dbEnum.pfnEnumProc = ListDeleteEnum;
+ dbEnum.szModule = sModule;
+ CallService(MS_DB_CONTACT_ENUMSETTINGS, NULL, (LPARAM)&dbEnum);
+
+ for (int i = 0; i < ListDeleteEnumData.ListSettings.GetSize(); i++)
+ db_unset(NULL, sModule, ListDeleteEnumData.ListSettings[i]);
+}
+
+int COptItem_ListCtrl::GetSelectedItemID(HWND hWnd)
+{
+ int Res = SendDlgItemMessage(hWnd, m_dlgItemID, LB_GETCURSEL, 0, 0);
+ return (Res == LB_ERR) ? -1 : Res; // i know that LB_ERR = -1 ;)
+}
+
+int COptItem_ListCtrl::SetSelectedItemID(HWND hWnd, int ID)
+{
+ int Res = SendDlgItemMessage(hWnd, m_dlgItemID, LB_SETCURSEL, ID, 0);
+ return (Res == LB_ERR) ? -1 : Res;
+}
+
+void COptItem_ListCtrl::Delete(HWND hWnd, int ID)
+{
+ _ASSERT(ID >= 0);
+ HWND hListView = GetDlgItem(hWnd, m_dlgItemID);
+ int Res = SendMessage(hListView, LB_DELETESTRING, ID, 0);
+ _ASSERT(Res != LB_ERR);
+ m_value.RemoveElem(ID);
+ m_bModified = true;
+}
+
+void COptItem_ListCtrl::ModifyItem(HWND hWnd, int ID, CListItem &Item)
+{ // changes the text of item with the specified ID
+ _ASSERT(ID >= 0);
+ HWND hListView = GetDlgItem(hWnd, m_dlgItemID);
+ SendMessage(hListView, WM_SETREDRAW, false, 0);
+ int CurSel = SendMessage(hListView, LB_GETCURSEL, 0, 0);
+ int TopIndex = SendMessage(hListView, LB_GETTOPINDEX, 0, 0);
+ int Res = SendMessage(hListView, LB_DELETESTRING, ID, 0);
+ _ASSERT(Res != LB_ERR);
+ Res = SendMessage(hListView, LB_INSERTSTRING, ID, (LPARAM)(TCHAR*)(Item.Text));
+ _ASSERT(Res != LB_ERR && Res != LB_ERRSPACE);
+ SendMessage(hListView, LB_SETCURSEL, CurSel, 0);
+ SendMessage(hListView, LB_SETTOPINDEX, TopIndex, 0);
+ SendMessage(hListView, WM_SETREDRAW, true, 0);
+ m_value[ID].Text = Item.Text;
+ m_bModified = true;
+}
+
+CListItem* COptItem_ListCtrl::InsertItem(HWND hWnd, int ID, CListItem &Item)
+// returns a pointer to the newly inserted item info
+// ID is position at which to insert the item; -1 = add to the end of the list
+{
+ HWND hListView = GetDlgItem(hWnd, m_dlgItemID);
+ int Res = SendMessage(hListView, LB_INSERTSTRING, ID, (LPARAM)(TCHAR*)(Item.Text)); // LB_INSERTSTRING doesn't sort the lists even with LBS_SORT style
+ _ASSERT(Res != LB_ERR && Res != LB_ERRSPACE);
+ int i = m_value.AddElem(Item);
+ m_bModified = true;
+ return &m_value[i];
+}
diff --git a/plugins/ClientChangeNotify/src/Options.h b/plugins/ClientChangeNotify/src/Options.h new file mode 100644 index 0000000000..4e4481da8b --- /dev/null +++ b/plugins/ClientChangeNotify/src/Options.h @@ -0,0 +1,532 @@ +/*
+ Options.h
+ Copyright (c) 2005-2008 Chervov Dmitry
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#pragma once
+
+#include "CString.h"
+#include "TMyArray.h"
+
+class COptItem
+{
+public:
+ COptItem() {}
+ COptItem(int m_dlgItemID, char *szDBSetting, int nValueSize, int lParam = 0, bool m_bReadOnly = false) :
+ m_dlgItemID(m_dlgItemID), nValueSize(nValueSize), sDBSetting(szDBSetting), lParam(lParam), m_bEnabled(true), m_bReadOnly(m_bReadOnly), m_bModified(false)
+ {
+ }
+
+ virtual ~COptItem() {}
+
+ virtual void DBToMem(const CString&, CString* = NULL) { m_bModified = false; }
+ virtual void MemToDB(const CString&, CString* = NULL) { m_bModified = false; }
+ virtual void WndToMem(HWND) {}
+ virtual void MemToWnd(HWND hWnd) { EnableWindow(GetDlgItem(hWnd, m_dlgItemID), m_bEnabled); }
+ void DBToMemToWnd(const CString &sModule, HWND hWnd, CString *sDBSettingPrefix = NULL) { DBToMem(sModule, sDBSettingPrefix); MemToWnd(hWnd); }
+ void WndToMemToDB(HWND hWnd, const CString &sModule, CString *sDBSettingPrefix = NULL) { WndToMem(hWnd); MemToDB(sModule, sDBSettingPrefix); }
+ virtual void CleanDBSettings(const CString &sModule, CString *sDBSettingPrefix = NULL) { db_unset(NULL, sModule, sDBSettingPrefix ? (*sDBSettingPrefix + sDBSetting) : sDBSetting); }; // TODO: also set m_value to m_defValue?
+
+ virtual void SetValue(INT_PTR) { m_bModified = true; }
+ virtual void SetDefValue(INT_PTR) {}
+ virtual INT_PTR GetValue() { return 0; }
+ virtual INT_PTR GetDefValue() { return 0; }
+
+ INT_PTR GetDBValue(const CString &sModule, CString *sDBSettingPrefix = NULL) { DBToMem(sModule, sDBSettingPrefix); return GetValue(); }
+ void SetDBValue(const CString &sModule, INT_PTR m_value, CString *sDBSettingPrefix = NULL) { SetValue(m_value); MemToDB(sModule, sDBSettingPrefix); }
+ INT_PTR GetDBValueCopy(const CString &sModule, CString *sDBSettingPrefix = NULL) { COptItem* Item = Copy(); Item->DBToMem(sModule, sDBSettingPrefix); INT_PTR m_value = Item->GetValue(); delete Item; return m_value; } // retrieves DB value, but doesn't affect current page/item state; beware! it doesn't work with string values / other dynamic pointers
+ void SetDBValueCopy(const CString &sModule, INT_PTR m_value, CString *sDBSettingPrefix = NULL) { COptItem* Item = Copy(); Item->SetValue(m_value); Item->MemToDB(sModule, sDBSettingPrefix); delete Item; }
+ INT_PTR GetWndValue(HWND hWnd) { WndToMem(hWnd); return GetValue(); }
+ void SetWndValue(HWND hWnd, INT_PTR m_value) { SetValue(m_value); MemToWnd(hWnd); }
+
+ void SetDlgItemID(int _DlgItemID) { m_dlgItemID = _DlgItemID; }
+ bool GetModified() { return m_bModified; }
+ void SetModified(bool _Modified) { m_bModified = _Modified; }
+
+ void Enable(bool bEnabled) { m_bEnabled = bEnabled; }
+ int GetParam() { return lParam; }
+ int GetID() { return m_dlgItemID; }
+
+ // virtual COptItem& operator = (const COptItem& Item) {return *this;};
+ virtual COptItem* Copy() { _ASSERT(0); return NULL; } // Attention! Free Copy() result when it's not needed anymore!
+
+ CString sDBSetting;
+
+protected:
+ int GetIntDBVal(const CString &sModule, int bSigned = false, CString *sDBSettingPrefix = NULL);
+ void SetIntDBVal(const CString &sModule, int m_value, CString *sDBSettingPrefix = NULL);
+ TCString GetStrDBVal(const CString &sModule, CString *sDBSettingPrefix = NULL);
+ void SetStrDBVal(const CString &sModule, TCString &Str, CString *sDBSettingPrefix = NULL);
+
+ int m_dlgItemID;
+ bool m_bEnabled;
+ bool m_bReadOnly;
+ bool m_bModified;
+ int nValueSize; // maximum pValue size in bytes
+ int lParam;
+};
+
+class COptItem_Generic : public COptItem
+{
+public:
+ COptItem_Generic() {}
+ COptItem_Generic(int m_dlgItemID, int lParam = 0) : COptItem(m_dlgItemID, NULL, 0, lParam) {}
+ virtual COptItem* Copy() { return new COptItem_Generic(*this); }
+};
+
+class COptItem_Edit : public COptItem
+{
+public:
+ COptItem_Edit() {}
+ COptItem_Edit(int m_dlgItemID, char *szDBSetting, int nMaxLen, TCHAR *szDefValue, int lParam = 0, bool m_bReadOnly = false)
+ : COptItem(m_dlgItemID, szDBSetting, nMaxLen, lParam, m_bReadOnly), sDefValue(szDefValue)
+ {}
+
+ void DBToMem(const CString &sModule, CString *sDBSettingPrefix = NULL) { sValue = GetStrDBVal(sModule, sDBSettingPrefix); COptItem::DBToMem(sModule, sDBSettingPrefix); }
+ void MemToDB(const CString &sModule, CString *sDBSettingPrefix = NULL) { SetStrDBVal(sModule, sValue, sDBSettingPrefix); COptItem::MemToDB(sModule, sDBSettingPrefix); }
+ void WndToMem(HWND hWnd) { GetDlgItemText(hWnd, m_dlgItemID, sValue.GetBuffer(nValueSize), nValueSize); sValue.ReleaseBuffer(); COptItem::MemToWnd(hWnd); }
+ void MemToWnd(HWND hWnd) { SetDlgItemText(hWnd, m_dlgItemID, sValue); COptItem::MemToWnd(hWnd); }
+
+ virtual void SetValue(INT_PTR m_value) { sValue = *(TCString*)m_value; COptItem::SetValue(m_value); }
+ virtual void SetDefValue(INT_PTR m_defValue) { sDefValue = *(TCString*)m_defValue; COptItem::SetDefValue(m_defValue); }
+
+ virtual INT_PTR GetValue() { return (INT_PTR)&sValue; }
+ virtual INT_PTR GetDefValue() { return (INT_PTR)&sDefValue; }
+
+ // COptItem_Edit& operator = (const COptItem_Edit& Item) {return *this;};
+ virtual COptItem* Copy() { return new COptItem_Edit(*this); }
+
+ TCString sDefValue;
+ TCString sValue;
+};
+
+
+class COptItem_IntEdit : public COptItem
+{
+public:
+ COptItem_IntEdit() {}
+ COptItem_IntEdit(int m_dlgItemID, char *szDBSetting, int nValueSize = DBVT_BYTE, int bSigned = true, int m_defValue = 0, int lParam = 0, bool m_bReadOnly = false)
+ : COptItem(m_dlgItemID, szDBSetting, nValueSize, lParam, m_bReadOnly), m_defValue(m_defValue), m_value(0), bSigned(bSigned)
+ {}
+
+ void DBToMem(const CString &sModule, CString *sDBSettingPrefix = NULL) { m_value = GetIntDBVal(sModule, bSigned, sDBSettingPrefix); COptItem::DBToMem(sModule, sDBSettingPrefix); }
+ void MemToDB(const CString &sModule, CString *sDBSettingPrefix = NULL) { SetIntDBVal(sModule, m_value, sDBSettingPrefix); COptItem::MemToDB(sModule, sDBSettingPrefix); }
+ void WndToMem(HWND hWnd) { m_value = GetDlgItemInt(hWnd, m_dlgItemID, NULL, bSigned); COptItem::WndToMem(hWnd); }
+ void MemToWnd(HWND hWnd) { SetDlgItemInt(hWnd, m_dlgItemID, m_value, bSigned); COptItem::MemToWnd(hWnd); }
+
+ virtual void SetValue(INT_PTR _Value) { this->m_value = _Value; COptItem::SetValue(_Value); }
+ virtual void SetDefValue(INT_PTR _DefValue) { this->m_defValue = _DefValue; COptItem::SetDefValue(_DefValue); }
+
+ virtual INT_PTR GetValue() { return m_value; }
+ virtual INT_PTR GetDefValue() { return m_defValue; }
+ virtual COptItem* Copy() { return new COptItem_IntEdit(*this); }
+
+ int m_defValue;
+ int m_value;
+ int bSigned;
+};
+
+
+class COptItem_Checkbox : public COptItem
+{
+public:
+ COptItem_Checkbox() {}
+ COptItem_Checkbox(int m_dlgItemID, char *szDBSetting, int nValueSize = DBVT_BYTE, int m_defValue = 0, int m_valueMask = 0, int lParam = 0, bool m_bReadOnly = false)
+ : COptItem(m_dlgItemID, szDBSetting, nValueSize, lParam, m_bReadOnly), m_defValue(m_defValue), m_value(0), m_valueMask(m_valueMask)
+ {}
+
+ void DBToMem(const CString &sModule, CString *sDBSettingPrefix = NULL);
+ void MemToDB(const CString &sModule, CString *sDBSettingPrefix = NULL);
+ void WndToMem(HWND hWnd);
+ void MemToWnd(HWND hWnd);
+
+ virtual void SetValue(INT_PTR _Value) { this->m_value = _Value; COptItem::SetValue(_Value); }
+ virtual void SetDefValue(INT_PTR _DefValue) { this->m_defValue = _DefValue; COptItem::SetDefValue(_DefValue); }
+
+ virtual INT_PTR GetValue() { return m_value; }
+ virtual INT_PTR GetDefValue() { return m_defValue; }
+
+ virtual COptItem* Copy() { return new COptItem_Checkbox(*this); }
+
+ int m_value;
+ int m_defValue;
+ int m_valueMask;
+};
+
+class COptItem_Radiobutton : public COptItem
+{
+public:
+ COptItem_Radiobutton() {}
+ COptItem_Radiobutton(int m_dlgItemID, char *szDBSetting, int nValueSize, int m_defValue, int m_valueMask, int lParam = 0, bool m_bReadOnly = false)
+ : COptItem(m_dlgItemID, szDBSetting, nValueSize, lParam, m_bReadOnly), m_defValue(m_defValue), m_value(0), m_valueMask(m_valueMask)
+ {}
+
+ void DBToMem(const CString &sModule, CString *sDBSettingPrefix = NULL) { m_value = (GetIntDBVal(sModule, false, sDBSettingPrefix) == m_valueMask) ? BST_CHECKED : BST_UNCHECKED; COptItem::DBToMem(sModule, sDBSettingPrefix); }
+ void MemToDB(const CString &sModule, CString *sDBSettingPrefix = NULL) { if ((m_value == BST_CHECKED)) SetIntDBVal(sModule, m_valueMask, sDBSettingPrefix); COptItem::MemToDB(sModule, sDBSettingPrefix); }
+ void WndToMem(HWND hWnd) { m_value = IsDlgButtonChecked(hWnd, m_dlgItemID); COptItem::WndToMem(hWnd); }
+ void MemToWnd(HWND hWnd) { CheckDlgButton(hWnd, m_dlgItemID, m_value ? BST_CHECKED : BST_UNCHECKED); COptItem::MemToWnd(hWnd); }
+
+ virtual void SetValue(INT_PTR _Value) { this->m_value = _Value; COptItem::SetValue(_Value); }
+ virtual void SetDefValue(INT_PTR _DefValue) { this->m_defValue = _DefValue; COptItem::SetDefValue(_DefValue); }
+
+ virtual INT_PTR GetValue() { return m_value; }
+ virtual INT_PTR GetDefValue() { return m_defValue; }
+
+ virtual COptItem* Copy() { return new COptItem_Radiobutton(*this); }
+
+ int m_value;
+ int m_defValue;
+ int m_valueMask;
+};
+
+class COptItem_Combobox : public COptItem
+{
+public:
+ COptItem_Combobox() {}
+ COptItem_Combobox(int m_dlgItemID, char *szDBSetting, int nValueSize = DBVT_BYTE, int m_defValue = 0, int lParam = 0, bool m_bReadOnly = false)
+ : COptItem(m_dlgItemID, szDBSetting, nValueSize, lParam, m_bReadOnly), m_defValue(m_defValue), m_value(0)
+ {}
+
+ void DBToMem(const CString &sModule, CString *sDBSettingPrefix = NULL) { m_value = GetIntDBVal(sModule, false, sDBSettingPrefix); COptItem::DBToMem(sModule, sDBSettingPrefix); }
+ void MemToDB(const CString &sModule, CString *sDBSettingPrefix = NULL) { SetIntDBVal(sModule, m_value, sDBSettingPrefix); COptItem::MemToDB(sModule, sDBSettingPrefix); }
+ void WndToMem(HWND hWnd) { m_value = SendDlgItemMessage(hWnd, m_dlgItemID, CB_GETITEMDATA, (WPARAM)SendDlgItemMessage(hWnd, m_dlgItemID, CB_GETCURSEL, 0, 0), 0); COptItem::WndToMem(hWnd); }
+ void MemToWnd(HWND hWnd) { SendDlgItemMessage(hWnd, m_dlgItemID, CB_SETCURSEL, m_value, 0); COptItem::MemToWnd(hWnd); }
+
+ virtual void SetValue(INT_PTR _Value) { this->m_value = _Value; COptItem::SetValue(_Value); }
+ virtual void SetDefValue(INT_PTR _DefValue) { this->m_defValue = _DefValue; COptItem::SetDefValue(_DefValue); }
+
+ virtual INT_PTR GetValue() { return m_value; }
+ virtual INT_PTR GetDefValue() { return m_defValue; }
+
+ virtual COptItem* Copy() { return new COptItem_Combobox(*this); }
+
+ int m_defValue;
+ int m_value;
+};
+
+class COptItem_Colourpicker : public COptItem
+{
+public:
+ COptItem_Colourpicker() {}
+ COptItem_Colourpicker(int m_dlgItemID, char *szDBSetting, int m_defValue = 0, int lParam = 0, bool m_bReadOnly = false)
+ : COptItem(m_dlgItemID, szDBSetting, DBVT_DWORD, lParam, m_bReadOnly), m_defValue(m_defValue), m_value(0)
+ {}
+
+ void DBToMem(const CString &sModule, CString *sDBSettingPrefix = NULL) { m_value = GetIntDBVal(sModule, false, sDBSettingPrefix); COptItem::DBToMem(sModule, sDBSettingPrefix); }
+ void MemToDB(const CString &sModule, CString *sDBSettingPrefix = NULL) { SetIntDBVal(sModule, m_value, sDBSettingPrefix); COptItem::MemToDB(sModule, sDBSettingPrefix); }
+ void WndToMem(HWND hWnd) { m_value = SendDlgItemMessage(hWnd, m_dlgItemID, CPM_GETCOLOUR, 0, 0); COptItem::WndToMem(hWnd); }
+ void MemToWnd(HWND hWnd) { SendDlgItemMessage(hWnd, m_dlgItemID, CPM_SETCOLOUR, 0, m_value); COptItem::MemToWnd(hWnd); }
+
+ virtual void SetValue(INT_PTR _Value) { this->m_value = _Value; COptItem::SetValue(_Value); }
+ virtual void SetDefValue(INT_PTR _DefValue) { this->m_defValue = _DefValue; COptItem::SetDefValue(_DefValue); }
+
+ virtual INT_PTR GetValue() { return m_value; }
+ virtual INT_PTR GetDefValue() { return m_defValue; }
+
+ virtual COptItem* Copy() { return new COptItem_Colourpicker(*this); }
+
+ DWORD m_defValue;
+ DWORD m_value;
+};
+
+
+class COptItem_Slider : public COptItem
+{
+public:
+ COptItem_Slider() {}
+ COptItem_Slider(int m_dlgItemID, char *szDBSetting, int nValueSize = DBVT_BYTE, int m_defValue = 0, int lParam = 0, bool m_bReadOnly = false)
+ : COptItem(m_dlgItemID, szDBSetting, nValueSize, lParam, m_bReadOnly), m_defValue(m_defValue), m_value(0)
+ {}
+
+ void DBToMem(const CString &sModule, CString *sDBSettingPrefix = NULL) { m_value = GetIntDBVal(sModule, false, sDBSettingPrefix); COptItem::DBToMem(sModule, sDBSettingPrefix); }
+ void MemToDB(const CString &sModule, CString *sDBSettingPrefix = NULL) { SetIntDBVal(sModule, m_value, sDBSettingPrefix); COptItem::MemToDB(sModule, sDBSettingPrefix); }
+ void WndToMem(HWND hWnd) { m_value = SendDlgItemMessage(hWnd, m_dlgItemID, TBM_GETPOS, 0, 0); COptItem::WndToMem(hWnd); }
+ void MemToWnd(HWND hWnd) { SendDlgItemMessage(hWnd, m_dlgItemID, TBM_SETPOS, true, m_value); COptItem::MemToWnd(hWnd); }
+
+ virtual void SetValue(INT_PTR _Value) { this->m_value = _Value; COptItem::SetValue(_Value); }
+ virtual void SetDefValue(INT_PTR _DefValue) { this->m_defValue = _DefValue; COptItem::SetDefValue(_DefValue); }
+
+ virtual INT_PTR GetValue() { return m_value; }
+ virtual INT_PTR GetDefValue() { return m_defValue; }
+ virtual COptItem* Copy() { return new COptItem_Slider(*this); }
+
+ int m_defValue;
+ int m_value;
+};
+
+
+class COptItem_IntDBSetting : public COptItem
+{
+public:
+ COptItem_IntDBSetting() {}
+ COptItem_IntDBSetting(int m_dlgItemID, char *szDBSetting, int nValueSize = DBVT_BYTE, int bSigned = true, int m_defValue = 0, int lParam = 0, bool m_bReadOnly = false)
+ : COptItem(m_dlgItemID, szDBSetting, nValueSize, lParam, m_bReadOnly), m_defValue(m_defValue), m_value(0), bSigned(bSigned)
+ {}
+
+ void DBToMem(const CString &sModule, CString *sDBSettingPrefix = NULL) { m_value = GetIntDBVal(sModule, bSigned, sDBSettingPrefix); COptItem::DBToMem(sModule, sDBSettingPrefix); }
+ void MemToDB(const CString &sModule, CString *sDBSettingPrefix = NULL) { SetIntDBVal(sModule, m_value, sDBSettingPrefix); COptItem::MemToDB(sModule, sDBSettingPrefix); }
+ void WndToMem(HWND hWnd) { COptItem::WndToMem(hWnd); }
+ void MemToWnd(HWND hWnd) { COptItem::MemToWnd(hWnd); }
+
+ virtual void SetValue(INT_PTR _Value) { this->m_value = _Value; COptItem::SetValue(_Value); }
+ virtual void SetDefValue(INT_PTR _DefValue) { this->m_defValue = _DefValue; COptItem::SetDefValue(_DefValue); }
+
+ virtual INT_PTR GetValue() { return m_value; }
+ virtual INT_PTR GetDefValue() { return m_defValue; }
+ virtual COptItem* Copy() { return new COptItem_IntDBSetting(*this); }
+
+ int m_value;
+ int m_defValue;
+ int bSigned;
+};
+
+
+class COptItem_BitDBSetting : public COptItem
+{
+public:
+ COptItem_BitDBSetting() {}
+ COptItem_BitDBSetting(int m_dlgItemID, char *szDBSetting, int nValueSize = DBVT_BYTE, int m_defValue = 0, int m_valueMask = 0, int lParam = 0, bool m_bReadOnly = false) : COptItem(m_dlgItemID, szDBSetting, nValueSize, lParam, m_bReadOnly), m_defValue(m_defValue), m_value(0), m_valueMask(m_valueMask) {}
+
+ void DBToMem(const CString &sModule, CString *sDBSettingPrefix = NULL);
+ void MemToDB(const CString &sModule, CString *sDBSettingPrefix = NULL);
+ void WndToMem(HWND hWnd) { COptItem::WndToMem(hWnd); }
+ void MemToWnd(HWND hWnd) { COptItem::MemToWnd(hWnd); }
+
+ virtual void SetValue(INT_PTR _Value) { this->m_value = _Value; COptItem::SetValue(_Value); }
+ virtual void SetDefValue(INT_PTR _DefValue) { this->m_defValue = _DefValue; COptItem::SetDefValue(_DefValue); }
+
+ virtual INT_PTR GetValue() { return m_value; }
+ virtual INT_PTR GetDefValue() { return m_defValue; }
+ virtual COptItem* Copy() { return new COptItem_BitDBSetting(*this); }
+
+ int m_value;
+ int m_defValue;
+ int m_valueMask;
+};
+
+
+class COptItem_StrDBSetting : public COptItem
+{
+public:
+ COptItem_StrDBSetting() {}
+ COptItem_StrDBSetting(int m_dlgItemID, char *szDBSetting, int nMaxLen, TCHAR *szDefValue, int lParam = 0, bool m_bReadOnly = false) : COptItem(m_dlgItemID, szDBSetting, nMaxLen, lParam, m_bReadOnly), sDefValue(szDefValue) {}
+ void DBToMem(const CString &sModule, CString *sDBSettingPrefix = NULL) { sValue = GetStrDBVal(sModule, sDBSettingPrefix); COptItem::DBToMem(sModule, sDBSettingPrefix); }
+ void MemToDB(const CString &sModule, CString *sDBSettingPrefix = NULL) { SetStrDBVal(sModule, sValue, sDBSettingPrefix); COptItem::MemToDB(sModule, sDBSettingPrefix); }
+ void WndToMem(HWND hWnd) { COptItem::WndToMem(hWnd); }
+ void MemToWnd(HWND hWnd) { COptItem::MemToWnd(hWnd); }
+
+ virtual void SetValue(INT_PTR _Value) { sValue = *(TCString*)_Value; COptItem::SetValue(_Value); }
+ virtual void SetDefValue(INT_PTR _DefValue) { sDefValue = *(TCString*)_DefValue; COptItem::SetDefValue(_DefValue); }
+
+ virtual INT_PTR GetValue() { return (INT_PTR)&sValue; }
+ virtual INT_PTR GetDefValue() { return (INT_PTR)&sDefValue; }
+
+ virtual COptItem* Copy() { return new COptItem_StrDBSetting(*this); }
+
+ TCString sDefValue;
+ TCString sValue;
+};
+
+
+// Tree item flags
+#define TIF_GROUP 1 // is a group
+#define TIF_EXPANDED 2 // item is expanded
+#define TIF_ENABLED 4 // item is checked (has sense when the tree has checkboxes)
+#define TIF_ROOTITEM 0x80 // item is a root item
+
+class CBaseTreeItem
+{
+public:
+ CBaseTreeItem();
+ CBaseTreeItem(TCString Title, int ID, int Flags) : Title(Title), ID(ID), Flags(Flags), hItem(NULL) {}
+
+ TCString Title;
+ int ID;
+ int Flags;
+ HTREEITEM hItem;
+};
+
+class CTreeItem : public CBaseTreeItem
+{
+public:
+ CTreeItem();
+ CTreeItem(TCString Title, int ParentID, int ID, int Flags = 0, TCString User_Str1 = NULL) :
+ CBaseTreeItem(Title, ID, Flags & ~TIF_ROOTITEM), ParentID(ParentID), User_Str1(User_Str1)
+ {
+ }
+
+ int ParentID;
+ TCString User_Str1;
+};
+
+class CTreeRootItem : public CBaseTreeItem
+{
+public:
+ CTreeRootItem();
+ CTreeRootItem(TCString Title, int ID, int Flags) : CBaseTreeItem(Title, ID, Flags | TIF_ROOTITEM) {}
+};
+
+typedef TMyArray<CTreeItem> TreeItemArray;
+typedef TMyArray<CTreeRootItem> TreeRootItemArray;
+
+#define TREECTRL_ROOTORDEROFFS -2
+#define ROOT_INDEX_TO_ORDER(i) (TREECTRL_ROOTORDEROFFS - (i))
+#define ROOT_ORDER_TO_INDEX(i) (TREECTRL_ROOTORDEROFFS - (i))
+
+#define TREEITEMTITLE_MAXLEN 128
+#define TREEITEM_DBSTR_TITLE "Title"
+#define TREEITEM_DBSTR_PARENT "Parent"
+#define TREEITEM_DBSTR_ORDER "Order"
+#define TREEITEM_DBSTR_FLAGS "Flags"
+
+// Tree control flags
+#define TREECTRL_FLAG_IS_SINGLE_LEVEL 1 // means that the tree items can't have children, i.e. the tree is a plain list of items
+#define TREECTRL_FLAG_HAS_CHECKBOXES 2
+//#define TREECTRL_FLAG_UNORDERED 4 TODO?
+
+class COptItem_TreeCtrl : public COptItem
+{
+public:
+ COptItem_TreeCtrl() {}
+ COptItem_TreeCtrl(int m_dlgItemID, char *szDBSetting, TreeItemArray &m_defValue, TreeRootItemArray RootItems, int lParam = 0, CString User_Str1_DBName = NULL, bool m_bReadOnly = false, int TreeFlags = 0) : COptItem(m_dlgItemID, szDBSetting, DBVT_DWORD, lParam, m_bReadOnly), m_defValue(m_defValue), RootItems(RootItems), User_Str1_DBName(User_Str1_DBName), TreeFlags(TreeFlags)
+ {
+ if (TreeFlags & TREECTRL_FLAG_IS_SINGLE_LEVEL) {
+ _ASSERT(!RootItems.GetSize()); // there can't be any root items when the tree is a plain list
+ this->RootItems.AddElem(CTreeRootItem(_T(""), 0, TIF_EXPANDED)); // TODO??
+ this->RootItems[0].hItem = TVI_ROOT;
+ }
+ }
+ ~COptItem_TreeCtrl() {}
+ void DBToMem(const CString &sModule, CString *sDBSettingPrefix = NULL);
+ void MemToDB(const CString &sModule, CString *sDBSettingPrefix = NULL);
+ void WndToMem(HWND hWnd);
+ void MemToWnd(HWND hWnd);
+ void CleanDBSettings(const CString &sModule, CString *sDBSettingPrefix = NULL);
+
+ virtual void SetValue(INT_PTR _Value) { this->m_value = *(TreeItemArray*)_Value; COptItem::SetValue(_Value); }
+ virtual void SetDefValue(INT_PTR _DefValue) { this->m_defValue = *(TreeItemArray*)_DefValue; COptItem::SetDefValue(_DefValue); }
+
+ virtual INT_PTR GetValue() { return (INT_PTR)&m_value; }
+ virtual INT_PTR GetDefValue() { return (INT_PTR)&m_defValue; }
+
+ virtual COptItem* Copy() { return new COptItem_TreeCtrl(*this); }
+
+ int IDToOrder(int ID);
+ int hItemToOrder(HTREEITEM hItem);
+ int GenerateID();
+ int GetSelectedItemID(HWND hWnd);
+ void Delete(HWND hWnd, int ID);
+ CTreeItem* InsertItem(HWND hWnd, CTreeItem &Item);
+ void MoveItem(HWND hWnd, HTREEITEM hItem, HTREEITEM hMoveTo);
+
+ TreeItemArray m_defValue, m_value;
+ TreeRootItemArray RootItems;
+ CString User_Str1_DBName;
+ int TreeFlags;
+
+protected:
+ void RecursiveDelete(HWND hWnd, int i);
+ int RecursiveMove(int ItemOrder, int ParentID, int InsertAtOrder);
+};
+
+
+class CListItem
+{
+public:
+ CListItem();
+ CListItem(TCString Text) : Text(Text) {}
+
+ TCString Text;
+};
+
+typedef TMyArray<CListItem> ListItemArray;
+
+#define LISTITEM_DBSTR_TEXT "Text"
+
+class COptItem_ListCtrl : public COptItem
+{
+public:
+ COptItem_ListCtrl() {}
+ COptItem_ListCtrl(int m_dlgItemID, char *szDBSetting, ListItemArray &m_defValue, int lParam = 0, bool m_bReadOnly = false) : COptItem(m_dlgItemID, szDBSetting, DBVT_DWORD, lParam, m_bReadOnly), m_defValue(m_defValue) {}
+ ~COptItem_ListCtrl() {}
+ void DBToMem(const CString &sModule, CString *sDBSettingPrefix = NULL);
+ void MemToDB(const CString &sModule, CString *sDBSettingPrefix = NULL);
+ void WndToMem(HWND hWnd);
+ void MemToWnd(HWND hWnd);
+ void CleanDBSettings(const CString &sModule, CString *sDBSettingPrefix = NULL);
+
+ virtual void SetValue(INT_PTR _Value) { this->m_value = *(ListItemArray*)_Value; COptItem::SetValue(_Value); }
+ virtual void SetDefValue(INT_PTR _DefValue) { this->m_defValue = *(ListItemArray*)_DefValue; COptItem::SetDefValue(_DefValue); }
+
+ virtual INT_PTR GetValue() { return (INT_PTR)&m_value; }
+ virtual INT_PTR GetDefValue() { return (INT_PTR)&m_defValue; }
+
+ virtual COptItem* Copy() { return new COptItem_ListCtrl(*this); }
+
+ int GetSelectedItemID(HWND hWnd); // returns -1 if there's no selection
+ int SetSelectedItemID(HWND hWnd, int ID);
+ void Delete(HWND hWnd, int ID);
+ CListItem* InsertItem(HWND hWnd, int ID, CListItem &Item);
+ void ModifyItem(HWND hWnd, int ID, CListItem &Item);
+
+ ListItemArray m_defValue, m_value;
+};
+
+
+class COptPage
+{
+public:
+ COptPage() : hWnd(NULL), sDBSettingPrefix("") {}
+ COptPage(char *szModule, HWND hWnd, CString sDBSettingPrefix = "") : sModule(szModule), hWnd(hWnd), sDBSettingPrefix(sDBSettingPrefix) {}
+ COptPage(const COptPage &Item);
+ ~COptPage();
+
+ void DBToMem();
+ void MemToDB();
+ void MemToPage(int OnlyEnable = 0);
+ void PageToMem();
+ void DBToMemToPage() { DBToMem(); MemToPage(); }
+ void PageToMemToDB() { PageToMem(); MemToDB(); }
+ void CleanDBSettings();
+
+ COptItem* Find(int m_dlgItemID);
+ INT_PTR GetValue(int m_dlgItemID) { return Find(m_dlgItemID)->GetValue(); }
+ void SetValue(int m_dlgItemID, INT_PTR m_value) { Find(m_dlgItemID)->SetValue(m_value); }
+
+ INT_PTR GetDBValue(int m_dlgItemID) { return Find(m_dlgItemID)->GetDBValue(sModule, &sDBSettingPrefix); }
+ void SetDBValue(int m_dlgItemID, INT_PTR m_value) { Find(m_dlgItemID)->SetDBValue(sModule, m_value, &sDBSettingPrefix); }
+
+ INT_PTR GetDBValueCopy(int m_dlgItemID) { return Find(m_dlgItemID)->GetDBValueCopy(sModule, &sDBSettingPrefix); }
+ void SetDBValueCopy(int m_dlgItemID, INT_PTR m_value) { Find(m_dlgItemID)->SetDBValueCopy(sModule, m_value, &sDBSettingPrefix); }
+
+ INT_PTR GetWndValue(int m_dlgItemID) { return Find(m_dlgItemID)->GetWndValue(hWnd); }
+ void SetWndValue(int m_dlgItemID, INT_PTR m_value) { Find(m_dlgItemID)->SetWndValue(hWnd, m_value); }
+
+ HWND GetWnd() { return hWnd; }
+ void SetWnd(HWND _hWnd) { _ASSERT(!this->hWnd || !_hWnd); this->hWnd = _hWnd; }
+
+ void Enable(int m_dlgItemID, bool m_bEnabled) { Find(m_dlgItemID)->Enable(m_bEnabled); }
+
+ bool GetModified();
+ void SetModified(bool m_bModified);
+
+ COptPage& operator = (const COptPage& Page);
+
+ HWND hWnd;
+ CString sModule, sDBSettingPrefix;
+ TMyArray<COptItem*, COptItem*> Items;
+};
diff --git a/plugins/ClientChangeNotify/src/CommonLibs/TMyArray.h b/plugins/ClientChangeNotify/src/TMyArray.h index 3e676bf816..3e676bf816 100644 --- a/plugins/ClientChangeNotify/src/CommonLibs/TMyArray.h +++ b/plugins/ClientChangeNotify/src/TMyArray.h diff --git a/plugins/ClientChangeNotify/src/CommonLibs/pcre.cpp b/plugins/ClientChangeNotify/src/pcre.cpp index 5fbc1d1f50..a57c0587c5 100644 --- a/plugins/ClientChangeNotify/src/CommonLibs/pcre.cpp +++ b/plugins/ClientChangeNotify/src/pcre.cpp @@ -17,7 +17,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "../stdafx.h"
+#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <crtdbg.h>
diff --git a/plugins/ClientChangeNotify/src/CommonLibs/pcre.h b/plugins/ClientChangeNotify/src/pcre.h index d6e80a4194..0a854af9c6 100644 --- a/plugins/ClientChangeNotify/src/CommonLibs/pcre.h +++ b/plugins/ClientChangeNotify/src/pcre.h @@ -18,7 +18,7 @@ */
#include "CString.h"
-#include "..\..\..\..\libs\pcre16\src\pcre.h"
+#include "..\..\..\libs\pcre16\src\pcre.h"
#pragma once
diff --git a/plugins/ClientChangeNotify/src/stdafx.h b/plugins/ClientChangeNotify/src/stdafx.h index a733839dc9..381703bcef 100644 --- a/plugins/ClientChangeNotify/src/stdafx.h +++ b/plugins/ClientChangeNotify/src/stdafx.h @@ -50,10 +50,10 @@ #include "m_fingerprint.h"
-#include "CommonLibs\TMyArray.h"
-#include "CommonLibs\Options.h"
-#include "CommonLibs\CString.h"
-#include "CommonLibs\pcre.h"
+#include "TMyArray.h"
+#include "Options.h"
+#include "CString.h"
+#include "pcre.h"
#include "resource.h"
#include "Misc.h"
@@ -116,7 +116,7 @@ static __inline CString LogMessage(const char *Format, ...) char szText[8096];
mir_strcpy(szText, LOG_PREFIX);
va_start(va, Format);
- mir_vsnprintf(szText + (lengthof(LOG_PREFIX) - 1), sizeof(szText) - (lengthof(LOG_PREFIX) - 1), Format, va);
+ mir_vsnprintf(szText + _countof(LOG_PREFIX)-1, _countof(szText) - (_countof(LOG_PREFIX)-1), Format, va);
va_end(va);
CallService(MS_NETLIB_LOG, NULL, (LPARAM)szText);
return CString(szText);
|