forked from irwir/eMule
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSmileySelector.cpp
275 lines (240 loc) · 7.64 KB
/
SmileySelector.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
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
//this file is part of eMule
//Copyright (C)2002-2008 Merkur ( strEmail.Format("%s@%s", "devteam", "emule-project.net") / http://www.emule-project.net )
//
//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., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "stdafx.h"
#include "emule.h"
#include "SmileySelector.h"
#include "VisualStylesXP.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
typedef struct {
LPCTSTR pszResource;
LPCTSTR pszSmileys;
} SSmiley;
SSmiley g_aSmileys[] =
{
#define ADD_SMILEY(res, sml) { _T( res ), _T( sml ) }
ADD_SMILEY("SMILEY_SMILE", ":-)"),
ADD_SMILEY("SMILEY_HAPPY", ":-))"),
ADD_SMILEY("SMILEY_LAUGH", ":-D"),
ADD_SMILEY("SMILEY_WINK", ";-)"),
ADD_SMILEY("SMILEY_TONGUE", ":-P"),
ADD_SMILEY("SMILEY_INTEREST", "=-)"),
ADD_SMILEY("SMILEY_SAD", ":-("),
ADD_SMILEY("SMILEY_CRY", ":'("),
ADD_SMILEY("SMILEY_DISGUST", ":-|"),
ADD_SMILEY("SMILEY_OMG", ":-O"),
ADD_SMILEY("SMILEY_SKEPTIC", ":-/"),
ADD_SMILEY("SMILEY_LOVE", ":-*"),
ADD_SMILEY("SMILEY_SMILEQ", ":-]"),
ADD_SMILEY("SMILEY_SADQ", ":-["),
ADD_SMILEY("SMILEY_PH34R", ":ph34r:"),
ADD_SMILEY("SMILEY_LOOKSIDE", ">_>"),
ADD_SMILEY("SMILEY_SEALED", ":-X"),
#undef ADD_SMILEY
};
//#define SHOW_SMILEY_SHORTCUTS // could be used for Noob mode
#define IDC_SMILEY_TOOLBAR 1
#define SMSEL_CMD_START 100
IMPLEMENT_DYNAMIC(CSmileySelector, CWnd)
BEGIN_MESSAGE_MAP(CSmileySelector, CWnd)
ON_WM_ACTIVATEAPP()
ON_WM_KILLFOCUS()
#ifndef SHOW_SMILEY_SHORTCUTS
ON_NOTIFY(TBN_GETINFOTIP, IDC_SMILEY_TOOLBAR, OnTbnSmileyGetInfoTip)
#endif
ON_WM_DESTROY()
END_MESSAGE_MAP()
CSmileySelector::CSmileySelector()
{
m_pwndEdit = NULL;
m_iBitmaps = 0;
}
CSmileySelector::~CSmileySelector()
{
}
void CSmileySelector::OnDestroy()
{
CImageList *piml = m_tb.GetImageList();
if (piml)
piml->DeleteImageList();
CWnd::OnDestroy();
}
BOOL CSmileySelector::Create(CWnd *pWndParent, const RECT *pRect, CEdit *pwndEdit)
{
m_pwndEdit = pwndEdit;
//////////////////////////////////////////////////////////////////////////
// Create the popup window
//
COLORREF crBackground = (g_xpStyle.IsAppThemed() && g_xpStyle.IsThemeActive()) ? COLOR_WINDOW : COLOR_BTNFACE;
CString strClassName = AfxRegisterWndClass(
CS_CLASSDC | CS_SAVEBITS | CS_HREDRAW | CS_VREDRAW,
AfxGetApp()->LoadStandardCursor(IDC_ARROW), (HBRUSH)(crBackground + 1), 0);
if (!CWnd::CreateEx(0, strClassName, _T(""),
WS_POPUP
| WS_BORDER
| WS_CLIPCHILDREN
| WS_CLIPSIBLINGS,
CRect(pRect->left, pRect->top, pRect->left, pRect->top),
pWndParent, 0, NULL))
return FALSE;
//////////////////////////////////////////////////////////////////////////
// Create the toolbar window
//
if (!m_tb.Create(WS_CHILD
| WS_VISIBLE
| WS_CLIPCHILDREN
| WS_CLIPSIBLINGS
| TBSTYLE_FLAT
| TBSTYLE_TRANSPARENT
| TBSTYLE_WRAPABLE
#ifndef SHOW_SMILEY_SHORTCUTS
| TBSTYLE_TOOLTIPS
#endif
| CCS_NOPARENTALIGN
| CCS_NODIVIDER,
CRect(0, 0, 0, 0), this, IDC_SMILEY_TOOLBAR))
return FALSE;
// Win98: Explicitly set to Unicode to receive Unicode notifications.
m_tb.SendMessage(CCM_SETUNICODEFORMAT, TRUE);
//////////////////////////////////////////////////////////////////////////
// Create toolbar image list with smileys
//
CSize sizSmiley(18, 18);
m_iBitmaps = 0;
CImageList iml;
iml.Create(sizSmiley.cx, sizSmiley.cy, theApp.m_iDfltImageListColorFlags | ILC_MASK, 0, 1);
for (int i = 0; i < _countof(g_aSmileys); i++)
{
iml.Add(CTempIconLoader(g_aSmileys[i].pszResource, sizSmiley.cx, sizSmiley.cy));
m_iBitmaps++;
}
CImageList *pimlOld = m_tb.SetImageList(&iml);
iml.Detach();
if (pimlOld)
pimlOld->DeleteImageList();
//////////////////////////////////////////////////////////////////////////
// Create toolbar button strings
//
#ifdef SHOW_SMILEY_SHORTCUTS
CString strStrings;
for (int i = 0; i < _countof(g_aSmileys); i++) {
strStrings += g_aSmileys[i].pszSmileys;
strStrings += _T('\001');
}
strStrings += _T('\001');
strStrings.Replace('\001', '\000');
m_tb.AddStrings(strStrings);
#endif
//////////////////////////////////////////////////////////////////////////
// Create toolbar buttons
//
TBBUTTON *tb = new TBBUTTON[m_iBitmaps];
for (int i = 0; i < m_iBitmaps; i++)
{
tb[i].iBitmap = i;
tb[i].idCommand = SMSEL_CMD_START + i;
tb[i].fsState = TBSTATE_ENABLED;
tb[i].fsStyle = BTNS_BUTTON;
tb[i].dwData = (DWORD_PTR)&g_aSmileys[i];
#ifdef SHOW_SMILEY_SHORTCUTS
tb[i].iString = i; // Looks interesting!! -> Smileys with shortcuts below
#else
tb[i].iString = -1;
#endif
}
m_tb.AddButtons(m_iBitmaps, tb);
delete[] tb;
// Set toolbar rows
CRect rcBounds;
rcBounds.SetRectEmpty();
m_tb.SetRows(3, TRUE, &rcBounds);
//////////////////////////////////////////////////////////////////////////
// Get toolbar size and adjust for borders and some strange offset at bottom
//
CRect rcToolBar;
m_tb.GetWindowRect(&rcToolBar);
int iToolBarWidth = rcToolBar.Width();
int iToolBarHeight = rcToolBar.Height();
if (GetStyle() & WS_BORDER)
iToolBarWidth += GetSystemMetrics(SM_CXBORDER)*2;
iToolBarHeight -= 2; // ??? = GetSystemMetrics(SM_CYBORDER)*2;
MoveWindow(pRect->left, pRect->top - iToolBarHeight, iToolBarWidth, iToolBarHeight);
ShowWindow(SW_SHOW);
return TRUE;
}
void CSmileySelector::OnActivateApp(BOOL bActive, DWORD dwThreadID)
{
CWnd::OnActivateApp(bActive, dwThreadID);
if (!bActive)
DestroyWindow();
}
void CSmileySelector::OnKillFocus(CWnd* pNewWnd)
{
CWnd::OnKillFocus(pNewWnd);
DestroyWindow();
}
BOOL CSmileySelector::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN && pMsg->wParam) {
DestroyWindow();
return TRUE;
}
return CWnd::PreTranslateMessage(pMsg);
}
BOOL CSmileySelector::OnCommand(WPARAM wParam, LPARAM lParam)
{
int iButtons = m_tb.GetButtonCount();
int iCmd = LOWORD(wParam);
if (m_pwndEdit != NULL && iCmd >= SMSEL_CMD_START && iCmd < SMSEL_CMD_START + iButtons)
{
int iStart, iEnd;
m_pwndEdit->GetSel(iStart, iEnd);
CString strEdit;
m_pwndEdit->GetWindowText(strEdit);
int iEditLen = strEdit.GetLength();
CString strInsert;
if ( (iStart > 0 && iStart < iEditLen - 1 && strEdit[iStart] != _T(' '))
|| (iStart == iEnd && iEnd >= iEditLen && iEditLen > 0 && strEdit[iEditLen - 1] != _T(' ')))
strInsert = _T(' ');
strInsert += g_aSmileys[iCmd - SMSEL_CMD_START].pszSmileys;
if (iEnd >= 0 && iEnd < iEditLen - 1 && strEdit[iEnd] != _T(' '))
strInsert += _T(' ');
m_pwndEdit->ReplaceSel(strInsert);
}
else
ASSERT(0);
return CWnd::OnCommand(wParam, lParam);
}
#ifndef SHOW_SMILEY_SHORTCUTS
void CSmileySelector::OnTbnSmileyGetInfoTip(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMTBGETINFOTIP pNMTBGIT = reinterpret_cast<LPNMTBGETINFOTIP>(pNMHDR);
if (pNMTBGIT->cchTextMax)
{
int iButtons = m_tb.GetButtonCount();
if (pNMTBGIT->iItem >= SMSEL_CMD_START && pNMTBGIT->iItem < SMSEL_CMD_START + iButtons)
{
_sntprintf(pNMTBGIT->pszText, pNMTBGIT->cchTextMax, _T(" %s "), g_aSmileys[pNMTBGIT->iItem - SMSEL_CMD_START].pszSmileys);
pNMTBGIT->pszText[pNMTBGIT->cchTextMax - 1] = _T('\0');
}
}
*pResult = 0;
}
#endif