1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
/*
UserinfoEx plugin for Miranda IM
Copyright:
© 2006-2010 DeathAxe, Yasnovidyashii, Merlin, K. Romanov, Kreol
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"
/**
* This functions fills a combobox given by @hCtrl with
* all items of the global timezone manager
*
* @param hDlg - HWND of the owning propertysheet page
* @param idCtrl - the ID of the control to associate with this class's instance
* @param pszSetting - the database setting to be handled by this class
*
* @return CTzCombo*
**/
CBaseCtrl* CTzCombo::CreateObj(HWND hDlg, WORD idCtrl, LPCSTR pszSetting)
{
HWND hCtrl = GetDlgItem(hDlg, idCtrl);
CTzCombo *ctrl = new CTzCombo(hDlg, idCtrl, pszSetting);
if (ctrl) {
//set the adress of our timezone handle as itemdata
//caller can obtain the handle htz to extract all relevant information
ctrl->_curSel = 0;
TimeZone_PrepareList(NULL, nullptr, hCtrl, TZF_PLF_CB);
}
return (ctrl);
}
/**
*
*
**/
CTzCombo::CTzCombo() : CBaseCtrl()
{
_curSel = CB_ERR;
}
/**
*
*
**/
CTzCombo::CTzCombo(HWND hDlg, WORD idCtrl, LPCSTR pszSetting)
: CBaseCtrl(hDlg, idCtrl, pszSetting)
{
_curSel = CB_ERR;
}
/**
* This method does a binary search in the sorted
* ComboBox for the item index. (new core tz interface)
*
* @param pTimeZone - LPTIME_ZONE_INFORMATION to find.
*
* @retval CB_ERR - item not found
* @retval 0...n - index of the combobox item
**/
int CTzCombo::Find(LPTIME_ZONE_INFORMATION pTimeZone) const
{
int nItemIndex;
int nItemCount = ComboBox_GetCount(_hwnd);
for (nItemIndex = 0; nItemIndex < nItemCount; nItemIndex++) {
if (pTimeZone == TimeZone_GetInfo((HANDLE)ComboBox_GetItemData(_hwnd, nItemIndex)))
return nItemIndex;
}
return CB_ERR;
}
/**
* This functions removes the user data from a combobox.
*
* @param hCtrl - HWND of the combobox
*
* @return nothing
**/
void CTzCombo::Release()
{
delete this;
}
/**
* This functions selects the combobox item which matches the contact's timezone.
*
* @param hCtrl - HWND of the combobox
* @param hContact - HANDLE of the contact whose timezone to select
* @param pszProto - the contact's protocol (not used by new core tz interface)
*
* @return _Flags.B.hasChanged member
**/
BOOL CTzCombo::OnInfoChanged(MCONTACT hContact, LPCSTR)
{
if (!_Flags.B.hasChanged) {
LPTIME_ZONE_INFORMATION pTimeZone;
pTimeZone = getTziByContact(hContact);
ComboBox_SetCurSel(_hwnd, Find(pTimeZone));
_curSel = ComboBox_GetCurSel(_hwnd);
SendMessage(GetParent(_hwnd), WM_TIMER, 0, 0);
}
return _Flags.B.hasChanged;
}
/**
* This method writes the combobox's item as the contact's timezone.
*
* @param hContact - HANDLE of the contact whose timezone to select
* @param pszProto - the contact's protocol (not used by new core tz interface)
*
* @return nothing
**/
void CTzCombo::OnApply(MCONTACT hContact, LPCSTR pszProto)
{
if (_Flags.B.hasChanged)
{
const char* pszModule = hContact ? USERINFO : pszProto;
if (_Flags.B.hasCustom || !hContact) {
//use new core tz interface
TimeZone_StoreListResult(hContact, nullptr, _hwnd, TZF_PLF_CB);
if (!hContact) {
_Flags.B.hasCustom = false;
_Flags.B.hasProto = true;
}
_Flags.B.hasChanged = false;
}
if (_Flags.B.hasChanged)
{
db_unset(hContact, USERINFO, SET_CONTACT_TIMEZONENAME);
db_unset(hContact, USERINFO, SET_CONTACT_TIMEZONEINDEX);
db_unset(hContact, pszModule, SET_CONTACT_TIMEZONE);
_Flags.B.hasChanged = false;
OnInfoChanged(hContact, pszProto);
}
InvalidateRect(_hwnd, nullptr, TRUE);
}
}
/**
* The user changed combobox selection, so mark it changed.
*
* @return nothing
**/
void CTzCombo::OnChangedByUser(WORD wChangedMsg)
{
if (wChangedMsg == CBN_SELCHANGE) {
int c = ComboBox_GetCurSel(_hwnd);
if (_curSel != c) {
if (!_Flags.B.hasChanged) {
_Flags.B.hasChanged = _Flags.B.hasCustom = true;
SendMessage(GetParent(GetParent(_hwnd)), PSM_CHANGED, 0, 0);
}
_curSel = c;
SendMessage(GetParent(_hwnd), WM_TIMER, 0, 0);
}
}
}
/**
* This method fills @szTime with the current time
* according to the combobox's selected timezone.
*
* @param szTime - string to fill with the current time
* @param cchTime - number of characters the string can take
*
* @return nothing
**/
void CTzCombo::GetTime(LPTSTR szTime, int cchTime)
{
TimeZone_PrintDateTime((HANDLE)ComboBox_GetItemData(_hwnd, _curSel), L"t", szTime, cchTime, 0);
}
|