OSDN Git Service

d36febd05c3eac276befdc9786152f2c713f197c
[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(RGB(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
49
50 VOID CChatData::SetChat(NicoLiveChat &chat_in){
51         
52         
53         this->anonymity = _ttol(chat_in.anonymity);
54         this->premium = _ttol(chat_in.premium);
55         this->chatBuf = chat_in.chatBuf;
56         this->no = _ttol(chat_in.no);
57
58         if(_tcscmp(chat_in.locale,TEXT("jp")) == 0){
59                 this->locale = cuntry::jp;
60         } else {
61                 this->locale = cuntry::unknown;
62         }
63         this->mail.reserve(chat_in.mailCount);
64         for(UINT_PTR index = 0;index < chat_in.mailCount ;index++){
65
66                 this->mail.push_back(chat_in.mail[index]);
67         }
68
69         this->name = chat_in.name;
70
71         this->listenerData = &listenerList.Register(chat_in.user_id);
72
73         
74         this->vpos = _ttol(chat_in.vpos);
75         this->thread = _ttol(chat_in.thread);
76         this->date = _ttol(chat_in.date);
77         
78
79
80         return;
81 }
82
83
84 //
85 //
86 //\83R\83\81\83\93\83g\83\8a\83X\83g\83N\83\89\83X
87 //////////////////////////////////////////////////////////////////////////
88
89 //\91I\91ð\8ds\8eæ\93¾\97p\83t\83@\83\93\83N\83V\83\87\83i\83\8b
90 struct GetCurSelFunc_t{
91
92         INT_PTR count;
93         BOOL findFlag;
94         GetCurSelFunc_t():
95                 count(0),
96                 findFlag(FALSE)
97                 {}
98
99         BOOL operator() (CChatData &target){
100                 count++;
101                 findFlag = target.selectFlag;
102                 return target.selectFlag;
103         }
104
105 };
106
107 CCommentList::CCommentList(){}
108
109 CCommentList::~CCommentList(){}
110
111 INT_PTR CCommentList::GetCurSel(){
112         GetCurSelFunc_t functa;
113         std::find_if(chatList.begin(),chatList.end(),functa);
114
115         return functa.findFlag == TRUE ? functa.count - 1 : -1;
116 }
117
118 CCommentList::iterator CCommentList::GetCurSelItem(){
119         auto rslt = std::find_if(chatList.begin(),chatList.end(),GetCurSelFunc_t());
120
121         return rslt;
122 }
123
124
125 VOID CCommentList::SetCurSel(INT_PTR cursel){
126         if(cursel < 0)return;
127         iterator data = chatList.begin();
128         std::advance(data,cursel);
129         data->selectFlag = TRUE;
130
131         return;
132 }
133
134
135 CCommentList::reference CCommentList::GetChatAt(UINT_PTR no){
136
137         iterator data = chatList.begin();
138         std::advance(data,no);
139         return *data;
140 }
141
142
143 UINT_PTR CCommentList::Size(){
144
145         return chatList.size();
146 }
147
148 BOOL CCommentList::empty(){
149
150         return chatList.empty();
151 }
152
153
154
155 CCommentList::iterator CCommentList::begin(){
156
157         return chatList.begin();
158 }
159
160 CCommentList::iterator CCommentList::end(){
161         
162         return chatList.end();
163 }
164
165
166 CCommentList::reverse_iterator CCommentList::rbegein(){
167
168         return chatList.rbegin();
169 }
170
171
172
173                 
174 CCommentList::reverse_iterator CCommentList::rend(){
175
176         return chatList.rend();
177 }
178
179 VOID CCommentList::OnDestroy(){
180         
181         chatList.clear();
182         
183 }
184
185 VOID CCommentList::OnConnect(){
186         OnDestroy();
187 }
188
189 CCommentList::reference CCommentList::back(){
190
191         return chatList.back();
192 }
193
194 VOID CListenerList::BkColorCollect(CListenerColorCollector &target){
195
196         iterator end = m_listenerList.end();
197         std::for_each(m_listenerList.begin(), end,target);
198 }
199
200 CListenerList::reference CListenerList::Register(LPCTSTR user_id){
201
202         ListenerPre listenerPre(user_id);
203
204         iterator begin = m_listenerList.begin();
205         iterator end = m_listenerList.end();
206
207         iterator rslt = std::find_if(begin,end,listenerPre);
208
209         
210
211         if(rslt == end){
212
213                 ListenerData insertData(user_id);
214                 
215
216                 m_listenerList.push_back(insertData);
217
218                 return m_listenerList.back();
219
220         }
221         
222         return *rslt;
223
224 }
225
226
227 }