This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NickList.cpp
187 lines (152 loc) · 4.39 KB
/
NickList.cpp
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
// NickList.cpp : implementation file
//
#include "stdafx.h"
#include "zsIRC.h"
#include "NickList.h"
#include "ChildView.h"
#include <wceres.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CNickList
CNickList::CNickList()
{
}
CNickList::~CNickList()
{
}
BEGIN_MESSAGE_MAP(CNickList, CListBox)
//{{AFX_MSG_MAP(CNickList)
ON_COMMAND(IDR_USER_QUERY, OnUserQuery)
ON_CONTROL_REFLECT(LBN_DBLCLK, OnDblclk)
ON_WM_LBUTTONDBLCLK()
ON_COMMAND(IDR_USER_WHOIS, OnUserWhois)
ON_COMMAND(IDR_USER_WHOISEX, OnUserWhoisex)
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CNickList message handlers
//DEL void CNickList::OnContextMenu(CWnd* pWnd, CPoint point)
//DEL {
//DEL // TODO: Add your message handler code here
//DEL // OnLButtonDown(NULL, point);
//DEL }
CString CNickList::GetCurSelNick()
{
int nIndex = GetCurSel();
if (nIndex<0) return CString("");
CString s;
GetText(nIndex,s);
// if (s[0] == _T('@')) s = s.Mid(1);
// if (s[0] == _T('+')) s = s.Mid(1);
while ( GetChannelBar()->sPrefixes.Find( s[0] ) != -1 ) s = s.Mid(1);
return s;
}
void CNickList::OnUserQuery()
{
// TODO: Add your command handler code here
CString s = GetCurSelNick();
if (!s.GetLength()) return;
GetChannelBar()->AddWindow(ZSIRC_WT_QUERY,s.LockBuffer());
}
void CNickList::OnDblclk()
{
// TODO: Add your control notification handler code here
}
void CNickList::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CString s = GetCurSelNick();
if (!s.GetLength()) return;
GetChannelBar()->AddWindow(ZSIRC_WT_QUERY,s.LockBuffer());
CListBox::OnLButtonDblClk(nFlags, point);
}
void CNickList::OnUserWhois()
{
// TODO: Add your command handler code here
CString s = GetCurSelNick();
if (!s.GetLength()) return;
CString str = _T("WHOIS ");
str += s;
GetChannelBar()->SendIRCMessage(str.LockBuffer());
}
void CNickList::OnUserWhoisex()
{
// TODO: Add your command handler code here
CString s = GetCurSelNick();
if (!s.GetLength()) return;
CString str = _T("WHOIS ");
str += s;
str += _T(" ");
str += s;
GetChannelBar()->SendIRCMessage(str.LockBuffer());
}
void CNickList::OnLButtonDown(UINT nFlags, CPoint point)
{
#if UNDER_CE >= 420
SHRGINFO shrgi = {0};
shrgi.cbSize = sizeof(SHRGINFO);
shrgi.hwndClient = m_hWnd;
shrgi.ptDown.x = point.x;
shrgi.ptDown.y = point.y;
shrgi.dwFlags = SHRG_RETURNCMD;
if(GN_CONTEXTMENU == ::SHRecognizeGesture(&shrgi)) {
ClientToScreen(&point);
CMenu mPopup;
mPopup.LoadMenu(IDR_USER);
CMenu * mSubmenu = mPopup.GetSubMenu(0);
mSubmenu->TrackPopupMenu(NULL, point.x, point.y, this);
} else Default();
#endif
}
int CNickList::Compare(CString& lpszText1, CString& lpszText2) {
// ASSERT(lpszText1 != NULL);
// ASSERT(lpszText2 != NULL);
int n1 = GetChannelBar()->sPrefixes.Find( lpszText1[0] );
int n2 = GetChannelBar()->sPrefixes.Find( lpszText2[0] );
if (n1!=-1) {
if (n2!=-1) {
if (n1 < n2) return -1;
if (n1 > n2) return 1;
int t = _tcsicmp(lpszText1.Mid(1), lpszText2.Mid(1));
//TRACE3("... _tcsicmp %s to %s = %d ... ",lpszText1.Mid(1), lpszText2.Mid(1), t);
return t;
} else {
return -1;
}
} else if (n2!=-1) {
return 1;
}
return _tcsicmp(lpszText1, lpszText2);
}
BOOL CNickList::PreCreateWindow(CREATESTRUCT &cs) {
if (!CListBox::PreCreateWindow (cs))
return FALSE;
cs.style &= ~(LBS_HASSTRINGS | LBS_SORT);
cs.style |= LBS_NOINTEGRALHEIGHT;
return TRUE;
}
int CNickList::InsertStringSorted(TCHAR*sz) {
//TRACE1("=== %s ===\n",sz);
for (int i=0; i<GetCount(); i++) {
CString pivot;
GetText(i,pivot);
//TRACE3("comparing %s to %s (%d)",sz,pivot,i);
if (Compare(pivot,CString(sz)) > 0) {
//TRACE0(" ... PASSED\n");
InsertString(i,sz);
return i;
}
//TRACE0(" ... next\n");
}
//TRACE0("LAST\n");
InsertString(-1,sz);
return -1;
}
CChannelBar * CNickList::GetChannelBar() {
return ((zsIRC_Wnd*)GetParent())->GetChannelBar();
}