OSDN Git Service

2012/01/27 17:30:53
[nlite/nlite.git] / nlite / nlite_chatData.cpp
1 #include "stdafx.h"
2 #include "nlite_include.h"
3
4 namespace nlite{
5 CListenerList nlite::listenerList;
6
7 //\83\8a\83X\83i\81[\8c\9f\8dõ\83I\83u\83W\83F\83N\83g
8 struct ListenerPre{
9
10         LPCTSTR user_id;
11
12         ListenerPre(LPCTSTR user_id_in):
13                 user_id(user_id_in)
14         {}
15
16         bool operator()(CListenerList::reference listenerData){
17
18                 return _tcscmp(user_id,listenerData.user_id) == 0;
19         }
20
21 };
22
23
24 ListenerData::ListenerData(LPCTSTR user_id_in):
25 user_id(user_id_in),
26 userName(TEXT("")),
27 bkColor(PALETTERGB(0,0,0)),
28 originBkFlag(FALSE)
29 {}
30
31 VOID ListenerData::SetBkColor(COLORREF bkColor_in){
32         bkColor = bkColor_in;
33         return;
34 }
35
36
37 VOID CCommentList::OnChatReceve(NicoLiveChat_P chatData_in, UINT_PTR commnetCountSum,CCommentListWindow &listWindow){
38
39         
40         CChatData chatData;
41         chatData.SetChat(*chatData_in);
42         
43 //      chatData.height = listWindow.CalcItemHeight(chatData);
44         
45         chatList.push_back(chatData);
46         return;
47 }
48 CChatData::ViewData::ViewData():
49                         sellLineColor(INIT_COLOR),
50                         stringColor(INIT_COLOR),
51                         backColor(INIT_COLOR),
52                   selectFlag(FALSE)
53                 {}
54
55 VOID CChatData::SetChat(NicoLiveChat &chat_in){
56         
57         
58         this->anonymity = _ttol(chat_in.anonymity);
59         this->premium = _ttol(chat_in.premium);
60         this->chatBuf = chat_in.chatBuf;
61         this->no = _ttol(chat_in.no);
62
63         if(_tcscmp(chat_in.locale,TEXT("jp")) == 0){
64                 this->locale = cuntry::jp;
65         } else {
66                 this->locale = cuntry::unknown;
67         }
68         this->mail.reserve(chat_in.mailCount);
69         for(UINT_PTR index = 0;index < chat_in.mailCount ;index++){
70
71                 this->mail.push_back(chat_in.mail[index]);
72         }
73
74         this->name = chat_in.name;
75
76         this->listenerData = &listenerList.Register(chat_in.user_id);
77
78         
79         this->vpos = _ttol(chat_in.vpos);
80         this->thread = _ttol(chat_in.thread);
81         this->date = _ttol(chat_in.date);
82         
83
84
85         return;
86 }
87
88
89 //
90 //
91 //\83R\83\81\83\93\83g\83\8a\83X\83g\83N\83\89\83X
92 //////////////////////////////////////////////////////////////////////////
93
94 //\91I\91ð\8ds\8eæ\93¾\97p\83t\83@\83\93\83N\83V\83\87\83i\83\8b
95 struct GetCurSelFunc_t{
96
97         INT_PTR count;
98         BOOL findFlag;
99         GetCurSelFunc_t():
100                 count(0)
101                 {}
102
103         BOOL operator() (CChatData &target){
104                 count++;
105                 return  target.viewData.selectFlag;
106         }
107
108 };
109
110 CCommentList::CCommentList(){}
111
112 CCommentList::~CCommentList(){}
113
114 INT_PTR CCommentList::GetCurSel(){
115         GetCurSelFunc_t functa;
116         auto end = this->end();
117         auto ite = this->begin();
118         INT_PTR count = 0;
119         for(;ite != end && ite->viewData.selectFlag == FALSE;++ite,++count);
120
121         return ite != end ? count : ERR;
122 }
123
124 CCommentList::iterator CCommentList::GetCurSelItem(){
125         auto rslt = std::find_if(chatList.begin(),chatList.end(),GetCurSelFunc_t());
126
127         return rslt;
128 }
129
130
131 VOID CCommentList::SetCurSel(INT_PTR cursel){
132         if(cursel < 0)goto end;
133         {
134                 auto curselItem = this->GetCurSelItem();
135         
136                 if(curselItem != this->end()){
137                         curselItem->viewData.selectFlag = FALSE;
138                 }
139         
140                 iterator data = chatList.begin();
141                 std::advance(data,cursel);
142                 data->viewData.selectFlag = TRUE;
143         }
144 end:
145
146         return;
147 }
148
149
150 CCommentList::reference CCommentList::GetChatAt(UINT_PTR no){
151
152         iterator data = chatList.begin();
153         std::advance(data,no);
154         return *data;
155 }
156
157
158 UINT_PTR CCommentList::Size(){
159
160         return chatList.size();
161 }
162
163 BOOL CCommentList::empty(){
164
165         return chatList.empty();
166 }
167
168
169
170 CCommentList::iterator CCommentList::begin(){
171
172         return chatList.begin();
173 }
174
175 CCommentList::iterator CCommentList::end(){
176         
177         return chatList.end();
178 }
179
180
181 CCommentList::reverse_iterator CCommentList::rbegein(){
182
183         
184         return chatList.rbegin();
185 }
186
187
188
189                 
190 CCommentList::reverse_iterator CCommentList::rend(){
191
192         return chatList.rend();
193 }
194
195 VOID CCommentList::OnDestroy(){
196         
197         chatList.clear();
198         
199 }
200
201 VOID CCommentList::OnConnect(){
202         OnDestroy();
203 }
204
205 CCommentList::reference CCommentList::back(){
206
207         return chatList.back();
208 }
209
210 VOID CListenerList::BkColorCollect(CListenerColorCollector &target){
211
212         iterator end = m_listenerList.end();
213         std::for_each(m_listenerList.begin(), end,target);
214 }
215
216 CListenerList::reference CListenerList::Register(LPCTSTR user_id){
217
218         ListenerPre listenerPre(user_id);
219
220         iterator begin = m_listenerList.begin();
221         iterator end = m_listenerList.end();
222
223         iterator rslt = std::find_if(begin,end,listenerPre);
224
225         
226
227         if(rslt == end){
228
229                 ListenerData insertData(user_id);
230                 
231
232                 m_listenerList.push_back(insertData);
233
234                 return m_listenerList.back();
235
236         }
237         
238         return *rslt;
239
240 }
241
242
243 }