summaryrefslogtreecommitdiff
path: root/plugins/UserInfoEx/dlg_propsheet.h
blob: 622eb8fa33d0216ed4190d10bb0c32cbe4acade1 (plain)
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/*
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.

===============================================================================

File name      : $HeadURL: https://userinfoex.googlecode.com/svn/trunk/dlg_propsheet.h $
Revision       : $Revision: 187 $
Last change on : $Date: 2010-09-08 16:05:54 +0400 (Ср, 08 сен 2010) $
Last change by : $Author: ing.u.horn $

===============================================================================
*/
#pragma once

typedef struct TPropSheet	PS, *LPPS;

class CPsHdr;
class CPsTree;

/***********************************************************************************************************
 * Tree item
 ***********************************************************************************************************/

class CPsTreeItem 
{
	INT				_idDlg;			// resource id of the property page
	LPDLGTEMPLATE	_pTemplate;		// locked template for the property page
	HINSTANCE		_hInst;			// instance handle of the owning plugin dll
	DLGPROC			_pfnDlgProc;	// dialog procedure for the property page
	HWND			_hWnd;			// window handle for the property page if shown jet
	DWORD			_dwFlags;		// some flags
	INT				_iPosition;		// initiating position if custom (used for sorting)
	LPARAM			_initParam;
	HANDLE			_hContact;		// contact the page is accociated with (may be a meta subcontact if details dialog is shown for a meta contact)
	LPCSTR			_pszProto;		// protocol the page is accociated with (is the contact's protocol if _hContact is not NULL)
	LPCSTR			_pszPrefix;		// pointer to the dialog owning contact's protocol

	HTREEITEM		_hItem;			// handle to the treeview item if visible (NULL if this item is hidden)
	INT				_iParent;		// index of the owning tree item
	INT				_iImage;		// index of treeview item's image
	BYTE			_bState;		// initial state of this treeitem
	LPSTR			_pszName;		// original name, given by plugin (not customized)
	LPTSTR			_ptszLabel;		// string to setting in db holding information about this treeitem

	LPCSTR	GlobalName();

	INT		Name(LPTSTR pszTitle, const BOOLEAN bIsUnicode);
	INT		ItemLabel(const BOOLEAN bReadDBValue);

	HICON	ProtoIcon();
	INT		Icon(HIMAGELIST hIml, OPTIONSDIALOGPAGE *odp, BOOLEAN bInitIconsOnly);

public:
	CPsTreeItem();
	~CPsTreeItem();
	INT Create(CPsHdr* pPsh, OPTIONSDIALOGPAGE *odp);

	__inline LPSTR Name() const { return _pszName; };
	__inline LPCSTR Proto() const { return _pszProto; };
	__inline LPTSTR Label() const { return _ptszLabel; };
	VOID Rename( const LPTSTR pszLabel );
	__inline HANDLE hContact() const { return _hContact; };

	__inline HWND Wnd() const { return _hWnd; };
	__inline INT DlgId() const { return _idDlg; };
	__inline HINSTANCE Inst() const { return _hInst; };

	__inline INT Image() const { return _iImage; };
	__inline INT Pos() const { return _iPosition; };
	__inline BYTE State() const { return _bState; };
	__inline HTREEITEM Hti() const { return _hItem; };
	__inline VOID Hti(HTREEITEM hti) { _hItem = hti; };
	__inline INT Parent() const { return _iParent; };
	__inline VOID Parent(const INT iParent) { _iParent = iParent; };

	__inline DWORD Flags() const { return _dwFlags; };
	__inline VOID Flags(DWORD dwFlags) { _dwFlags = dwFlags; };
	__inline VOID AddFlags(DWORD dwFlags) { _dwFlags |= dwFlags; };
	__inline VOID RemoveFlags(DWORD dwFlags) { _dwFlags &= ~dwFlags; };

	BOOLEAN HasName(const LPCSTR pszName) const;

	LPCSTR PropertyKey(LPCSTR pszProperty);
	LPCSTR GlobalPropertyKey(LPCSTR pszProperty);
	LPCSTR IconKey();

	LPSTR ParentItemName();
	HWND CreateWnd(LPPS pPs);
	
	WORD DBSaveItemState(LPCSTR pszGroup, INT iItemPosition, UINT iState, DWORD dwFlags);

	// notification handlers
	VOID OnInfoChanged();
	VOID OnPageIconsChanged();
	VOID OnIconsChanged(CPsTree *pTree);
};


/***********************************************************************************************************
 * Tree control
 ***********************************************************************************************************/

#define MAX_TINAME			64

// internal setting strings
#define SET_LASTITEM		"LastItem"
#define SET_ITEM_LABEL		"label"
#define SET_ITEM_GROUP		"group"
#define SET_ITEM_STATE		"state"
#define SET_ITEM_POS		"pos"
#define TREE_ROOTITEM		"<ROOT>"

// treeview states
#define DBTVIS_INVISIBLE	0
#define DBTVIS_NORMAL		1
#define DBTVIS_EXPANDED		2

// flags for the treeview
#define PSTVF_SORTTREE		0x00010000
#define PSTVF_GROUPS		0x00020000
#define PSTVF_LABEL_CHANGED	0x00040000
#define PSTVF_POS_CHANGED	0x00080000
#define PSTVF_STATE_CHANGED	0x00100000
#define PSTVF_INITICONS		0x00200000		// flag that indicates the AddPage handler to load only basic stuff

class CPsTree {
	HWND					_hWndTree;
	HIMAGELIST				_hImages;
	CPsTreeItem**			_pItems;
	INT						_curItem;
	INT						_numItems;
	DWORD					_dwFlags;
	HWND					_hLabelEdit;
	HTREEITEM				_hDragItem;
	BOOLEAN					_isDragging;
	LPPS					_pPs;

	WORD	SaveItemsState(LPCSTR pszGroup, HTREEITEM hRootItem, INT& iItem);

public:
	CPsTree(LPPS pPs);
	~CPsTree();
	
	__inline VOID BeginDrag(HTREEITEM hDragItem) { _isDragging = TRUE; _hDragItem = hDragItem; };
	__inline VOID EndDrag() { _isDragging = FALSE; _hDragItem = NULL; };
	__inline BOOLEAN IsDragging() const { return _isDragging; };
	__inline HTREEITEM DragItem() const { return _hDragItem; };

	__inline DWORD Flags() const { return _dwFlags; };
	__inline VOID Flags(DWORD dwFlags) { _dwFlags = dwFlags; };
	__inline VOID AddFlags(DWORD dwFlags) { _dwFlags |= dwFlags; };
	__inline VOID RemoveFlags(DWORD dwFlags) { _dwFlags &= ~dwFlags; };

	__inline INT NumItems() const { return _numItems; };
	__inline HWND Window() const { return _hWndTree; };
	__inline HIMAGELIST ImageList() const { return _hImages; };
	__inline BOOLEAN IsIndexValid(const INT index) const { return (index >= 0 && index < _numItems); };
	
	__inline CPsTreeItem* TreeItem(INT index) const { return (IsIndexValid(index) ? _pItems[index] : NULL); };
	__inline HTREEITEM TreeItemHandle(INT index) const { return (IsIndexValid(index) ? _pItems[index]->Hti() : NULL); };

	__inline INT CurrentItemIndex() const { return _curItem; };
	__inline CPsTreeItem* CurrentItem() const { return TreeItem(CurrentItemIndex()); };

	INT				AddDummyItem(LPCSTR pszGroup);
	BOOLEAN			Create(HWND hWndTree, CPsHdr* pPsh);
	BOOLEAN			InitTreeItems(LPWORD needWidth);
	
	VOID			HideItem(const INT iPageIndex);
	HTREEITEM ShowItem(const INT iPageIndex, LPWORD needWidth);

	HTREEITEM MoveItem(HTREEITEM hItem, HTREEITEM hInsertAfter, BOOLEAN bAsChild = FALSE);
	VOID			SaveState();
	VOID			DBResetState();

	INT				FindItemIndexByHandle(HTREEITEM hItem);
	INT				FindItemIndexByName(LPCSTR pszName);

	CPsTreeItem*	FindItemByName(LPCSTR pszName);
	CPsTreeItem*	FindItemByHandle(HTREEITEM hItem);
	HTREEITEM		FindItemHandleByName(LPCSTR pszName);
	CPsTreeItem*	FindItemByResource(HINSTANCE hInst, INT idDlg);

	INT				BeginLabelEdit( HTREEITEM hItem );
	INT				EndLabelEdit( const BOOLEAN bSave );
	VOID			PopupMenu();
	
	VOID			OnIconsChanged();
	BOOLEAN			OnInfoChanged();
	BOOLEAN			OnSelChanging();
	VOID			OnSelChanged(LPNMTREEVIEW lpnmtv);
	VOID			OnCancel();
	INT				OnApply();
};

/***********************************************************************************************************
 * common stuff
 ***********************************************************************************************************/

// internal flags for the PSP structure
#define PSPF_CHANGED				4096
#define PSPF_PROTOPREPENDED			8192	// the first token of the title is the protocol

#define PSF_PROTOPAGESONLY			64		// load only contact's protocol pages
#define PSF_PROTOPAGESONLY_INIT		128

class CPsUpload;

class CPsHdr 
{
public:
	DWORD			_dwSize;		// size of this class in bytes
	HANDLE			_hContact;		// handle to the owning contact
	LPCSTR			_pszProto;		// owning contact's protocol 
	LPCSTR			_pszPrefix;		// name prefix for treeitem settings
	CPsTreeItem**	_pPages;		// the pages
	WORD			_numPages;		// number of pages
	DWORD			_dwFlags;		// some option flags
	HIMAGELIST		_hImages;		// the imagelist with all tree item icons
	LIST<TCHAR>		_ignore;		// list of to skipp items when adding metasubcontacts pages
	INT				_nSubContact;	// index of a current subcontact

	CPsHdr();
	~CPsHdr();
	
	VOID Free_pPages();

};

struct TAckInfo 
{
	HANDLE	hContact;
	LPINT/*PINT_PTR*/	acks;
	INT		count;
};

struct TPropSheet 
{
	// dialogs owner
	HANDLE		hContact;
	CHAR		pszProto[MAXMODULELABELLENGTH];

	HANDLE		hProtoAckEvent;		// eventhook for protocol acks
	HANDLE		hSettingChanged;	// eventhook searching for changed contact information
	HANDLE		hIconsChanged;		// eventhook for changed icons in icolib
	HFONT		hCaptionFont;
	HFONT		hBoldFont;
	RECT		rcDisplay;
	BYTE		updateAnimFrame;
	CHAR		szUpdating[64];
	DWORD		dwFlags;

	TAckInfo	*infosUpdated;
	INT			nSubContacts;
	
	// controls
	HWND		hDlg;
	CPsTree		*pTree;
	CPsUpload	*pUpload;
};

VOID	DlgContactInfoInitTreeIcons();
VOID	DlgContactInfoLoadModule();
VOID	DlgContactInfoUnLoadModule();