Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(271)

Side by Side Diff: fpdfsdk/src/fxedit/fxet_list.cpp

Issue 453133004: clang-format all code (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "../../include/fxedit/fxet_stub.h" 7 #include "../../include/fxedit/fxet_stub.h"
8 #include "../../include/fxedit/fxet_edit.h" 8 #include "../../include/fxedit/fxet_edit.h"
9 #include "../../include/fxedit/fxet_list.h" 9 #include "../../include/fxedit/fxet_list.h"
10 10
11 /* ------------------------------- CFX_ListItem -------------------------------- -- */ 11 /* ------------------------------- CFX_ListItem
12 12 * ---------------------------------- */
13 CFX_ListItem::CFX_ListItem() : m_pEdit(NULL), 13
14 m_bSelected(FALSE), 14 CFX_ListItem::CFX_ListItem()
15 m_bCaret(FALSE), 15 : m_pEdit(NULL),
16 m_rcListItem(0.0f,0.0f,0.0f,0.0f) 16 m_bSelected(FALSE),
17 { 17 m_bCaret(FALSE),
18 m_pEdit = IFX_Edit::NewEdit(); 18 m_rcListItem(0.0f, 0.0f, 0.0f, 0.0f) {
19 ASSERT(m_pEdit != NULL); 19 m_pEdit = IFX_Edit::NewEdit();
20 20 ASSERT(m_pEdit != NULL);
21 m_pEdit->SetAlignmentV(1); 21
22 m_pEdit->Initialize(); 22 m_pEdit->SetAlignmentV(1);
23 } 23 m_pEdit->Initialize();
24 24 }
25 CFX_ListItem::~CFX_ListItem() 25
26 { 26 CFX_ListItem::~CFX_ListItem() {
27 IFX_Edit::DelEdit(m_pEdit); 27 IFX_Edit::DelEdit(m_pEdit);
28 } 28 }
29 29
30 void CFX_ListItem::SetFontMap(IFX_Edit_FontMap * pFontMap) 30 void CFX_ListItem::SetFontMap(IFX_Edit_FontMap* pFontMap) {
31 { 31 if (m_pEdit)
32 if (m_pEdit) 32 m_pEdit->SetFontMap(pFontMap);
33 m_pEdit->SetFontMap(pFontMap); 33 }
34 } 34
35 35 IFX_Edit* CFX_ListItem::GetEdit() const {
36 IFX_Edit* CFX_ListItem::GetEdit() const 36 return m_pEdit;
37 { 37 }
38 return m_pEdit; 38
39 } 39 IFX_Edit_Iterator* CFX_ListItem::GetIterator() const {
40 40 if (m_pEdit)
41 IFX_Edit_Iterator* CFX_ListItem::GetIterator() const 41 return m_pEdit->GetIterator();
42 { 42
43 if (m_pEdit) 43 return NULL;
44 return m_pEdit->GetIterator(); 44 }
45 45
46 return NULL; 46 void CFX_ListItem::SetRect(const CLST_Rect& rect) {
47 } 47 m_rcListItem = rect;
48 48 }
49 void CFX_ListItem::SetRect(const CLST_Rect & rect) 49
50 { 50 CLST_Rect CFX_ListItem::GetRect() const {
51 m_rcListItem = rect; 51 return m_rcListItem;
52 } 52 }
53 53
54 CLST_Rect CFX_ListItem::GetRect() const 54 FX_BOOL CFX_ListItem::IsSelected() const {
55 { 55 return m_bSelected;
56 return m_rcListItem; 56 }
57 } 57
58 58 void CFX_ListItem::SetSelect(FX_BOOL bSelected) {
59 FX_BOOL CFX_ListItem::IsSelected() const 59 m_bSelected = bSelected;
60 { 60 }
61 return m_bSelected; 61
62 } 62 FX_BOOL CFX_ListItem::IsCaret() const {
63 63 return m_bCaret;
64 void CFX_ListItem::SetSelect(FX_BOOL bSelected) 64 }
65 { 65
66 m_bSelected = bSelected; 66 void CFX_ListItem::SetCaret(FX_BOOL bCaret) {
67 } 67 m_bCaret = bCaret;
68 68 }
69 FX_BOOL CFX_ListItem::IsCaret() const 69
70 { 70 void CFX_ListItem::SetText(FX_LPCWSTR text) {
71 return m_bCaret; 71 if (m_pEdit)
72 } 72 m_pEdit->SetText(text);
73 73 }
74 void CFX_ListItem::SetCaret(FX_BOOL bCaret) 74
75 { 75 void CFX_ListItem::SetFontSize(FX_FLOAT fFontSize) {
76 m_bCaret = bCaret; 76 if (m_pEdit)
77 } 77 m_pEdit->SetFontSize(fFontSize);
78 78 }
79 void CFX_ListItem::SetText(FX_LPCWSTR text) 79
80 { 80 FX_FLOAT CFX_ListItem::GetItemHeight() const {
81 if (m_pEdit) 81 if (m_pEdit)
82 m_pEdit->SetText(text); 82 return m_pEdit->GetContentRect().Height();
83 } 83
84 84 return 0.0f;
85 void CFX_ListItem::SetFontSize(FX_FLOAT fFontSize) 85 }
86 { 86
87 if (m_pEdit) 87 FX_WORD CFX_ListItem::GetFirstChar() const {
88 m_pEdit->SetFontSize(fFontSize); 88 CPVT_Word word;
89 } 89
90 90 if (IFX_Edit_Iterator* pIterator = GetIterator()) {
91 FX_FLOAT CFX_ListItem::GetItemHeight() const 91 pIterator->SetAt(1);
92 { 92 pIterator->GetWord(word);
93 if (m_pEdit) 93 }
94 return m_pEdit->GetContentRect().Height(); 94
95 95 return word.Word;
96 return 0.0f; 96 }
97 } 97
98 98 CFX_WideString CFX_ListItem::GetText() const {
99 FX_WORD CFX_ListItem::GetFirstChar() const 99 if (m_pEdit)
100 { 100 return m_pEdit->GetText();
101 CPVT_Word word; 101
102 102 return L"";
103 if (IFX_Edit_Iterator* pIterator = GetIterator()) 103 }
104 { 104
105 pIterator->SetAt(1); 105 /* ------------------------------------ CFX_List
106 pIterator->GetWord(word); 106 * --------------------------------- */
107 } 107
108 108 CFX_List::CFX_List() : m_fFontSize(0.0f), m_pFontMap(NULL), m_bMultiple(FALSE) {
109 return word.Word; 109 }
110 } 110
111 111 CFX_List::~CFX_List() {
112 CFX_WideString CFX_ListItem::GetText() const 112 Empty();
113 { 113 }
114 if (m_pEdit) 114
115 return m_pEdit->GetText(); 115 void CFX_List::Empty() {
116 116 for (FX_INT32 i = 0, sz = m_aListItems.GetSize(); i < sz; i++)
117 return L""; 117 delete m_aListItems.GetAt(i);
118 } 118
119 119 m_aListItems.RemoveAll();
120 /* ------------------------------------ CFX_List ------------------------------- -- */ 120 }
121 121
122 CFX_List::CFX_List() : m_fFontSize(0.0f), m_pFontMap(NULL), m_bMultiple(FALSE) 122 void CFX_List::SetFontMap(IFX_Edit_FontMap* pFontMap) {
123 { 123 m_pFontMap = pFontMap;
124 } 124 }
125 125
126 CFX_List::~CFX_List() 126 void CFX_List::SetFontSize(FX_FLOAT fFontSize) {
127 { 127 m_fFontSize = fFontSize;
128 Empty(); 128 }
129 } 129
130 130 void CFX_List::AddItem(FX_LPCWSTR str) {
131 void CFX_List::Empty() 131 if (CFX_ListItem* pListItem = new CFX_ListItem()) {
132 { 132 pListItem->SetFontMap(m_pFontMap);
133 for (FX_INT32 i=0,sz=m_aListItems.GetSize(); i<sz; i++) 133 pListItem->SetFontSize(m_fFontSize);
134 delete m_aListItems.GetAt(i); 134 pListItem->SetText(str);
135 135 m_aListItems.Add(pListItem);
136 m_aListItems.RemoveAll(); 136 }
137 } 137 }
138 138
139 void CFX_List::SetFontMap(IFX_Edit_FontMap * pFontMap) 139 void CFX_List::ReArrange(FX_INT32 nItemIndex) {
140 { 140 FX_FLOAT fPosY = 0.0f;
141 m_pFontMap = pFontMap; 141
142 } 142 if (CFX_ListItem* pPrevItem = m_aListItems.GetAt(nItemIndex - 1))
143 143 fPosY = pPrevItem->GetRect().bottom;
144 void CFX_List::SetFontSize(FX_FLOAT fFontSize) 144
145 { 145 for (FX_INT32 i = nItemIndex, sz = m_aListItems.GetSize(); i < sz; i++) {
146 m_fFontSize = fFontSize; 146 if (CFX_ListItem* pListItem = m_aListItems.GetAt(i)) {
147 } 147 FX_FLOAT fListItemHeight = pListItem->GetItemHeight();
148 148 pListItem->SetRect(CLST_Rect(0.0f, fPosY, 0.0f, fPosY + fListItemHeight));
149 void CFX_List::AddItem(FX_LPCWSTR str) 149 fPosY += fListItemHeight;
150 { 150 }
151 if (CFX_ListItem * pListItem = new CFX_ListItem()) 151 }
152 { 152
153 pListItem->SetFontMap(m_pFontMap); 153 SetContentRect(CLST_Rect(0.0f, 0.0f, 0.0f, fPosY));
154 pListItem->SetFontSize(m_fFontSize); 154 }
155 pListItem->SetText(str); 155
156 m_aListItems.Add(pListItem); 156 IFX_Edit* CFX_List::GetItemEdit(FX_INT32 nIndex) const {
157 } 157 if (CFX_ListItem* pListItem = m_aListItems.GetAt(nIndex)) {
158 } 158 return pListItem->GetEdit();
159 159 }
160 void CFX_List::ReArrange(FX_INT32 nItemIndex) 160
161 { 161 return NULL;
162 FX_FLOAT fPosY = 0.0f; 162 }
163 163
164 if (CFX_ListItem * pPrevItem = m_aListItems.GetAt(nItemIndex - 1)) 164 FX_INT32 CFX_List::GetCount() const {
165 fPosY = pPrevItem->GetRect().bottom; 165 return m_aListItems.GetSize();
166 166 }
167 for (FX_INT32 i=nItemIndex,sz=m_aListItems.GetSize(); i<sz; i++) 167
168 { 168 CPDF_Rect CFX_List::GetPlateRect() const {
169 if (CFX_ListItem * pListItem = m_aListItems.GetAt(i)) 169 return CFX_ListContainer::GetPlateRect();
170 { 170 }
171 FX_FLOAT fListItemHeight = pListItem->GetItemHeight(); 171
172 pListItem->SetRect(CLST_Rect(0.0f,fPosY,0.0f,fPosY + fLi stItemHeight)); 172 CPDF_Rect CFX_List::GetContentRect() const {
173 fPosY += fListItemHeight; 173 return InnerToOuter(CFX_ListContainer::GetContentRect());
174 } 174 }
175 } 175
176 176 FX_FLOAT CFX_List::GetFontSize() const {
177 SetContentRect(CLST_Rect(0.0f,0.0f,0.0f,fPosY)); 177 return m_fFontSize;
178 } 178 }
179 179
180 IFX_Edit * CFX_List::GetItemEdit(FX_INT32 nIndex) const 180 FX_INT32 CFX_List::GetItemIndex(const CPDF_Point& point) const {
181 { 181 CPDF_Point pt = OuterToInner(point);
182 if (CFX_ListItem * pListItem = m_aListItems.GetAt(nIndex)) 182
183 { 183 FX_BOOL bFirst = TRUE;
184 return pListItem->GetEdit(); 184 FX_BOOL bLast = TRUE;
185 } 185
186 186 for (FX_INT32 i = 0, sz = m_aListItems.GetSize(); i < sz; i++) {
187 return NULL; 187 if (CFX_ListItem* pListItem = m_aListItems.GetAt(i)) {
188 } 188 CLST_Rect rcListItem = pListItem->GetRect();
189 189
190 FX_INT32 CFX_List::GetCount() const 190 if (FX_EDIT_IsFloatBigger(pt.y, rcListItem.top)) {
191 { 191 bFirst = FALSE;
192 return m_aListItems.GetSize(); 192 }
193 } 193
194 194 if (FX_EDIT_IsFloatSmaller(pt.y, rcListItem.bottom)) {
195 CPDF_Rect CFX_List::GetPlateRect() const 195 bLast = FALSE;
196 { 196 }
197 return CFX_ListContainer::GetPlateRect(); 197
198 } 198 if (pt.y >= rcListItem.top && pt.y < rcListItem.bottom) {
199 199 return i;
200 CPDF_Rect CFX_List::GetContentRect() const 200 }
201 { 201 }
202 return InnerToOuter(CFX_ListContainer::GetContentRect()); 202 }
203 } 203
204 204 if (bFirst)
205 FX_FLOAT CFX_List::GetFontSize() const 205 return 0;
206 { 206 if (bLast)
207 return m_fFontSize; 207 return m_aListItems.GetSize() - 1;
208 } 208
209 209 return -1;
210 FX_INT32 CFX_List::GetItemIndex(const CPDF_Point & point) const 210 }
211 { 211
212 CPDF_Point pt = OuterToInner(point); 212 FX_FLOAT CFX_List::GetFirstHeight() const {
213 213 if (CFX_ListItem* pListItem = m_aListItems.GetAt(0)) {
214 FX_BOOL bFirst = TRUE; 214 return pListItem->GetItemHeight();
215 FX_BOOL bLast = TRUE; 215 }
216 216
217 for (FX_INT32 i=0,sz=m_aListItems.GetSize(); i<sz; i++) 217 return 1.0f;
218 { 218 }
219 if (CFX_ListItem * pListItem = m_aListItems.GetAt(i)) 219
220 { 220 FX_INT32 CFX_List::GetFirstSelected() const {
221 CLST_Rect rcListItem = pListItem->GetRect(); 221 for (FX_INT32 i = 0, sz = m_aListItems.GetSize(); i < sz; i++) {
222 222 if (CFX_ListItem* pListItem = m_aListItems.GetAt(i)) {
223 if (FX_EDIT_IsFloatBigger(pt.y, rcListItem.top)) 223 if (pListItem->IsSelected())
224 { 224 return i;
225 bFirst = FALSE; 225 }
226 } 226 }
227 227 return -1;
228 if (FX_EDIT_IsFloatSmaller(pt.y, rcListItem.bottom)) 228 }
229 { 229
230 bLast = FALSE; 230 FX_INT32 CFX_List::GetLastSelected() const {
231 } 231 for (FX_INT32 i = m_aListItems.GetSize() - 1; i >= 0; i--) {
232 232 if (CFX_ListItem* pListItem = m_aListItems.GetAt(i)) {
233 if (pt.y >= rcListItem.top && pt.y < rcListItem.bottom) 233 if (pListItem->IsSelected())
234 { 234 return i;
235 return i; 235 }
236 } 236 }
237 } 237 return -1;
238 } 238 }
239 239
240 if (bFirst) return 0; 240 FX_WCHAR CFX_List::Toupper(FX_WCHAR c) const {
241 if (bLast) return m_aListItems.GetSize()-1; 241 if ((c >= 'a') && (c <= 'z'))
242 242 c = c - ('a' - 'A');
243 return -1; 243 return c;
244 } 244 }
245 245
246 FX_FLOAT CFX_List::GetFirstHeight() const 246 FX_INT32 CFX_List::FindNext(FX_INT32 nIndex, FX_WCHAR nChar) const {
247 { 247 FX_INT32 nCircleIndex = nIndex;
248 if (CFX_ListItem * pListItem = m_aListItems.GetAt(0)) 248
249 { 249 for (FX_INT32 i = 0, sz = m_aListItems.GetSize(); i < sz; i++) {
250 return pListItem->GetItemHeight(); 250 nCircleIndex++;
251 } 251 if (nCircleIndex >= sz)
252 252 nCircleIndex = 0;
253 return 1.0f; 253
254 } 254 if (CFX_ListItem* pListItem = m_aListItems.GetAt(nCircleIndex)) {
255 255 if (Toupper(pListItem->GetFirstChar()) == Toupper(nChar))
256 FX_INT32 CFX_List::GetFirstSelected() const 256 return nCircleIndex;
257 { 257 }
258 for (FX_INT32 i=0,sz=m_aListItems.GetSize(); i<sz; i++) 258 }
259 { 259
260 if (CFX_ListItem * pListItem = m_aListItems.GetAt(i)) 260 return nCircleIndex;
261 { 261 }
262 if (pListItem->IsSelected()) 262
263 return i; 263 CPDF_Rect CFX_List::GetItemRect(FX_INT32 nIndex) const {
264 } 264 if (CFX_ListItem* pListItem = m_aListItems.GetAt(nIndex)) {
265 } 265 CPDF_Rect rcItem = pListItem->GetRect();
266 return -1; 266 rcItem.left = 0.0f;
267 } 267 rcItem.right = GetPlateRect().Width();
268 268 return InnerToOuter(rcItem);
269 FX_INT32 CFX_List::GetLastSelected() const 269 }
270 { 270
271 for (FX_INT32 i=m_aListItems.GetSize()-1; i>=0; i--) 271 return CPDF_Rect();
272 { 272 }
273 if (CFX_ListItem * pListItem = m_aListItems.GetAt(i)) 273
274 { 274 FX_BOOL CFX_List::IsItemSelected(FX_INT32 nIndex) const {
275 if (pListItem->IsSelected()) 275 if (CFX_ListItem* pListItem = m_aListItems.GetAt(nIndex)) {
276 return i; 276 return pListItem->IsSelected();
277 } 277 }
278 } 278
279 return -1; 279 return FALSE;
280 } 280 }
281 281
282 FX_WCHAR CFX_List::Toupper(FX_WCHAR c) const 282 void CFX_List::SetItemSelect(FX_INT32 nItemIndex, FX_BOOL bSelected) {
283 { 283 if (CFX_ListItem* pListItem = m_aListItems.GetAt(nItemIndex)) {
284 if ( (c >= 'a') && (c <= 'z') ) 284 pListItem->SetSelect(bSelected);
285 c = c - ('a' - 'A'); 285 }
286 return c; 286 }
287 } 287
288 288 void CFX_List::SetItemCaret(FX_INT32 nItemIndex, FX_BOOL bCaret) {
289 FX_INT32 CFX_List::FindNext(FX_INT32 nIndex,FX_WCHAR nChar) const 289 if (CFX_ListItem* pListItem = m_aListItems.GetAt(nItemIndex)) {
290 { 290 pListItem->SetCaret(bCaret);
291 FX_INT32 nCircleIndex = nIndex; 291 }
292 292 }
293 for (FX_INT32 i=0,sz=m_aListItems.GetSize(); i<sz; i++) 293
294 { 294 void CFX_List::SetMultipleSel(FX_BOOL bMultiple) {
295 nCircleIndex ++; 295 m_bMultiple = bMultiple;
296 if (nCircleIndex >= sz) nCircleIndex = 0; 296 }
297 297
298 if (CFX_ListItem * pListItem = m_aListItems.GetAt(nCircleIndex)) 298 FX_BOOL CFX_List::IsMultipleSel() const {
299 { 299 return m_bMultiple;
300 if (Toupper(pListItem->GetFirstChar()) == Toupper(nChar) ) 300 }
301 return nCircleIndex; 301
302 } 302 FX_BOOL CFX_List::IsValid(FX_INT32 nItemIndex) const {
303 } 303 return nItemIndex >= 0 && nItemIndex < m_aListItems.GetSize();
304 304 }
305 return nCircleIndex; 305
306 } 306 CFX_WideString CFX_List::GetItemText(FX_INT32 nIndex) const {
307 307 if (CFX_ListItem* pListItem = m_aListItems.GetAt(nIndex)) {
308 CPDF_Rect CFX_List::GetItemRect(FX_INT32 nIndex) const 308 return pListItem->GetText();
309 { 309 }
310 if (CFX_ListItem * pListItem = m_aListItems.GetAt(nIndex)) 310
311 { 311 return L"";
312 CPDF_Rect rcItem = pListItem->GetRect(); 312 }
313 rcItem.left = 0.0f; 313
314 rcItem.right = GetPlateRect().Width(); 314 /* ------------------------------------ CPLST_Select
315 return InnerToOuter(rcItem); 315 * ---------------------------------- */
316 } 316
317 317 CPLST_Select::CPLST_Select() {
318 return CPDF_Rect(); 318 }
319 } 319
320 320 CPLST_Select::~CPLST_Select() {
321 FX_BOOL CFX_List::IsItemSelected(FX_INT32 nIndex) const 321 for (FX_INT32 i = 0, sz = m_aItems.GetSize(); i < sz; i++)
322 { 322 delete m_aItems.GetAt(i);
323 if (CFX_ListItem * pListItem = m_aListItems.GetAt(nIndex)) 323
324 { 324 m_aItems.RemoveAll();
325 return pListItem->IsSelected(); 325 }
326 } 326
327 327 void CPLST_Select::Add(FX_INT32 nItemIndex) {
328 return FALSE; 328 FX_INT32 nIndex = Find(nItemIndex);
329 } 329
330 330 if (nIndex < 0)
331 void CFX_List::SetItemSelect(FX_INT32 nItemIndex, FX_BOOL bSelected) 331 m_aItems.Add(new CPLST_Select_Item(nItemIndex, 1));
332 { 332 else {
333 if (CFX_ListItem * pListItem = m_aListItems.GetAt(nItemIndex)) 333 if (CPLST_Select_Item* pItem = m_aItems.GetAt(nIndex)) {
334 { 334 pItem->nState = 1;
335 pListItem->SetSelect(bSelected); 335 }
336 } 336 }
337 } 337 }
338 338
339 void CFX_List::SetItemCaret(FX_INT32 nItemIndex, FX_BOOL bCaret) 339 void CPLST_Select::Add(FX_INT32 nBeginIndex, FX_INT32 nEndIndex) {
340 { 340 if (nBeginIndex > nEndIndex) {
341 if (CFX_ListItem * pListItem = m_aListItems.GetAt(nItemIndex)) 341 FX_INT32 nTemp = nEndIndex;
342 { 342 nEndIndex = nBeginIndex;
343 pListItem->SetCaret(bCaret); 343 nBeginIndex = nTemp;
344 } 344 }
345 } 345
346 346 for (FX_INT32 i = nBeginIndex; i <= nEndIndex; i++)
347 void CFX_List::SetMultipleSel(FX_BOOL bMultiple) 347 Add(i);
348 { 348 }
349 m_bMultiple = bMultiple; 349
350 } 350 void CPLST_Select::Sub(FX_INT32 nItemIndex) {
351 351 for (FX_INT32 i = m_aItems.GetSize() - 1; i >= 0; i--) {
352 FX_BOOL CFX_List::IsMultipleSel() const 352 if (CPLST_Select_Item* pItem = m_aItems.GetAt(i))
353 { 353 if (pItem->nItemIndex == nItemIndex)
354 return m_bMultiple; 354 pItem->nState = -1;
355 } 355 }
356 356 }
357 FX_BOOL CFX_List::IsValid(FX_INT32 nItemIndex) const 357
358 { 358 void CPLST_Select::Sub(FX_INT32 nBeginIndex, FX_INT32 nEndIndex) {
359 return nItemIndex >= 0 && nItemIndex < m_aListItems.GetSize(); 359 if (nBeginIndex > nEndIndex) {
360 } 360 FX_INT32 nTemp = nEndIndex;
361 361 nEndIndex = nBeginIndex;
362 CFX_WideString CFX_List::GetItemText(FX_INT32 nIndex) const 362 nBeginIndex = nTemp;
363 { 363 }
364 if (CFX_ListItem * pListItem = m_aListItems.GetAt(nIndex)) 364
365 { 365 for (FX_INT32 i = nBeginIndex; i <= nEndIndex; i++)
366 return pListItem->GetText(); 366 Sub(i);
367 } 367 }
368 368
369 return L""; 369 FX_INT32 CPLST_Select::Find(FX_INT32 nItemIndex) const {
370 } 370 for (FX_INT32 i = 0, sz = m_aItems.GetSize(); i < sz; i++) {
371 371 if (CPLST_Select_Item* pItem = m_aItems.GetAt(i)) {
372 /* ------------------------------------ CPLST_Select --------------------------- ------- */ 372 if (pItem->nItemIndex == nItemIndex)
373 373 return i;
374 CPLST_Select::CPLST_Select() 374 }
375 { 375 }
376 } 376
377 377 return -1;
378 CPLST_Select::~CPLST_Select() 378 }
379 { 379
380 for (FX_INT32 i=0,sz=m_aItems.GetSize(); i<sz; i++) 380 FX_BOOL CPLST_Select::IsExist(FX_INT32 nItemIndex) const {
381 delete m_aItems.GetAt(i); 381 return Find(nItemIndex) >= 0;
382 382 }
383 m_aItems.RemoveAll(); 383
384 } 384 FX_INT32 CPLST_Select::GetCount() const {
385 385 return m_aItems.GetSize();
386 void CPLST_Select::Add(FX_INT32 nItemIndex) 386 }
387 { 387
388 FX_INT32 nIndex = Find(nItemIndex); 388 FX_INT32 CPLST_Select::GetItemIndex(FX_INT32 nIndex) const {
389 389 if (nIndex >= 0 && nIndex < m_aItems.GetSize())
390 if (nIndex < 0) 390 if (CPLST_Select_Item* pItem = m_aItems.GetAt(nIndex))
391 m_aItems.Add(new CPLST_Select_Item(nItemIndex,1)); 391 return pItem->nItemIndex;
392 else 392
393 { 393 return -1;
394 if (CPLST_Select_Item * pItem = m_aItems.GetAt(nIndex)) 394 }
395 { 395
396 pItem->nState = 1; 396 FX_INT32 CPLST_Select::GetState(FX_INT32 nIndex) const {
397 } 397 if (nIndex >= 0 && nIndex < m_aItems.GetSize())
398 } 398 if (CPLST_Select_Item* pItem = m_aItems.GetAt(nIndex))
399 } 399 return pItem->nState;
400 400
401 void CPLST_Select::Add(FX_INT32 nBeginIndex, FX_INT32 nEndIndex) 401 return 0;
402 { 402 }
403 if (nBeginIndex > nEndIndex) 403
404 { 404 void CPLST_Select::DeselectAll() {
405 FX_INT32 nTemp = nEndIndex; 405 for (FX_INT32 i = 0, sz = m_aItems.GetSize(); i < sz; i++) {
406 nEndIndex = nBeginIndex; 406 if (CPLST_Select_Item* pItem = m_aItems.GetAt(i)) {
407 nBeginIndex = nTemp; 407 pItem->nState = -1;
408 } 408 }
409 409 }
410 for (FX_INT32 i=nBeginIndex; i<=nEndIndex; i++) Add(i); 410 }
411 } 411
412 412 void CPLST_Select::Done() {
413 void CPLST_Select::Sub(FX_INT32 nItemIndex) 413 for (FX_INT32 i = m_aItems.GetSize() - 1; i >= 0; i--) {
414 { 414 if (CPLST_Select_Item* pItem = m_aItems.GetAt(i)) {
415 for (FX_INT32 i=m_aItems.GetSize()-1; i>=0; i--) 415 if (pItem->nState == -1) {
416 { 416 delete pItem;
417 if (CPLST_Select_Item * pItem = m_aItems.GetAt(i)) 417 m_aItems.RemoveAt(i);
418 if (pItem->nItemIndex == nItemIndex) 418 } else {
419 pItem->nState = -1; 419 pItem->nState = 0;
420 } 420 }
421 } 421 }
422 422 }
423 void CPLST_Select::Sub(FX_INT32 nBeginIndex, FX_INT32 nEndIndex) 423 }
424 { 424
425 if (nBeginIndex > nEndIndex) 425 /* ------------------------------------ CFX_ListCtrl
426 { 426 * --------------------------------- */
427 FX_INT32 nTemp = nEndIndex; 427
428 nEndIndex = nBeginIndex; 428 CFX_ListCtrl::CFX_ListCtrl()
429 nBeginIndex = nTemp; 429 : m_pNotify(NULL),
430 } 430 m_bNotifyFlag(FALSE),
431 431 m_ptScrollPos(0.0f, 0.0f),
432 for (FX_INT32 i=nBeginIndex; i<=nEndIndex; i++) Sub(i); 432 m_nSelItem(-1),
433 } 433 m_nFootIndex(-1),
434 434 m_bCtrlSel(FALSE),
435 FX_INT32 CPLST_Select::Find(FX_INT32 nItemIndex) const 435 m_nCaretIndex(-1) {
436 { 436 }
437 for (FX_INT32 i=0,sz=m_aItems.GetSize(); i<sz; i++) 437
438 { 438 CFX_ListCtrl::~CFX_ListCtrl() {
439 if (CPLST_Select_Item * pItem = m_aItems.GetAt(i)) 439 }
440 { 440
441 if (pItem->nItemIndex == nItemIndex) 441 void CFX_ListCtrl::SetNotify(IFX_List_Notify* pNotify) {
442 return i; 442 m_pNotify = pNotify;
443 } 443 }
444 } 444
445 445 CPDF_Point CFX_ListCtrl::InToOut(const CPDF_Point& point) const {
446 return -1; 446 CPDF_Rect rcPlate = GetPlateRect();
447 } 447
448 448 return CPDF_Point(point.x - (m_ptScrollPos.x - rcPlate.left),
449 FX_BOOL CPLST_Select::IsExist(FX_INT32 nItemIndex) const 449 point.y - (m_ptScrollPos.y - rcPlate.top));
450 { 450 }
451 return Find(nItemIndex) >= 0; 451
452 } 452 CPDF_Point CFX_ListCtrl::OutToIn(const CPDF_Point& point) const {
453 453 CPDF_Rect rcPlate = GetPlateRect();
454 FX_INT32 CPLST_Select::GetCount() const 454
455 { 455 return CPDF_Point(point.x + (m_ptScrollPos.x - rcPlate.left),
456 return m_aItems.GetSize(); 456 point.y + (m_ptScrollPos.y - rcPlate.top));
457 } 457 }
458 458
459 FX_INT32 CPLST_Select::GetItemIndex(FX_INT32 nIndex) const 459 CPDF_Rect CFX_ListCtrl::InToOut(const CPDF_Rect& rect) const {
460 { 460 CPDF_Point ptLeftBottom = InToOut(CPDF_Point(rect.left, rect.bottom));
461 if (nIndex >= 0 && nIndex < m_aItems.GetSize()) 461 CPDF_Point ptRightTop = InToOut(CPDF_Point(rect.right, rect.top));
462 if (CPLST_Select_Item * pItem = m_aItems.GetAt(nIndex)) 462
463 return pItem->nItemIndex; 463 return CPDF_Rect(ptLeftBottom.x, ptLeftBottom.y, ptRightTop.x, ptRightTop.y);
464 464 }
465 return -1; 465
466 } 466 CPDF_Rect CFX_ListCtrl::OutToIn(const CPDF_Rect& rect) const {
467 467 CPDF_Point ptLeftBottom = OutToIn(CPDF_Point(rect.left, rect.bottom));
468 FX_INT32 CPLST_Select::GetState(FX_INT32 nIndex) const 468 CPDF_Point ptRightTop = OutToIn(CPDF_Point(rect.right, rect.top));
469 { 469
470 if (nIndex >= 0 && nIndex < m_aItems.GetSize()) 470 return CPDF_Rect(ptLeftBottom.x, ptLeftBottom.y, ptRightTop.x, ptRightTop.y);
471 if (CPLST_Select_Item * pItem = m_aItems.GetAt(nIndex)) 471 }
472 return pItem->nState; 472
473 473 void CFX_ListCtrl::OnMouseDown(const CPDF_Point& point,
474 return 0; 474 FX_BOOL bShift,
475 } 475 FX_BOOL bCtrl) {
476 476 FX_INT32 nHitIndex = this->GetItemIndex(point);
477 void CPLST_Select::DeselectAll() 477
478 { 478 if (IsMultipleSel()) {
479 for (FX_INT32 i=0,sz=m_aItems.GetSize(); i<sz; i++) 479 if (bCtrl) {
480 { 480 if (IsItemSelected(nHitIndex)) {
481 if (CPLST_Select_Item * pItem = m_aItems.GetAt(i)) 481 m_aSelItems.Sub(nHitIndex);
482 { 482 SelectItems();
483 pItem->nState = -1; 483 m_bCtrlSel = FALSE;
484 } 484 } else {
485 } 485 m_aSelItems.Add(nHitIndex);
486 } 486 SelectItems();
487 487 m_bCtrlSel = TRUE;
488 void CPLST_Select::Done() 488 }
489 { 489
490 for (FX_INT32 i=m_aItems.GetSize()-1; i>=0; i--) 490 m_nFootIndex = nHitIndex;
491 { 491 } else if (bShift) {
492 if (CPLST_Select_Item * pItem = m_aItems.GetAt(i)) 492 m_aSelItems.DeselectAll();
493 { 493 m_aSelItems.Add(m_nFootIndex, nHitIndex);
494 if (pItem->nState == -1) 494 SelectItems();
495 { 495 } else {
496 delete pItem; 496 m_aSelItems.DeselectAll();
497 m_aItems.RemoveAt(i); 497 m_aSelItems.Add(nHitIndex);
498 } 498 SelectItems();
499 else 499
500 { 500 m_nFootIndex = nHitIndex;
501 pItem->nState = 0; 501 }
502 } 502
503 } 503 SetCaret(nHitIndex);
504 } 504 } else {
505 } 505 SetSingleSelect(nHitIndex);
506 506 }
507 /* ------------------------------------ CFX_ListCtrl --------------------------- ------ */ 507
508 508 if (!this->IsItemVisible(nHitIndex))
509 CFX_ListCtrl::CFX_ListCtrl() : m_pNotify(NULL), 509 this->ScrollToListItem(nHitIndex);
510 m_bNotifyFlag(FALSE), 510 }
511 m_ptScrollPos(0.0f,0.0f), 511
512 m_nSelItem(-1), 512 void CFX_ListCtrl::OnMouseMove(const CPDF_Point& point,
513 m_nFootIndex(-1), 513 FX_BOOL bShift,
514 m_bCtrlSel(FALSE), 514 FX_BOOL bCtrl) {
515 m_nCaretIndex(-1) 515 FX_INT32 nHitIndex = this->GetItemIndex(point);
516 { 516
517 } 517 if (IsMultipleSel()) {
518 518 if (bCtrl) {
519 CFX_ListCtrl::~CFX_ListCtrl() 519 if (m_bCtrlSel)
520 { 520 m_aSelItems.Add(m_nFootIndex, nHitIndex);
521 } 521 else
522 522 m_aSelItems.Sub(m_nFootIndex, nHitIndex);
523 void CFX_ListCtrl::SetNotify(IFX_List_Notify * pNotify) 523
524 { 524 SelectItems();
525 m_pNotify = pNotify; 525 } else {
526 } 526 m_aSelItems.DeselectAll();
527 527 m_aSelItems.Add(m_nFootIndex, nHitIndex);
528 CPDF_Point CFX_ListCtrl::InToOut(const CPDF_Point & point) const 528 SelectItems();
529 { 529 }
530 CPDF_Rect rcPlate = GetPlateRect(); 530
531 531 SetCaret(nHitIndex);
532 return CPDF_Point(point.x - (m_ptScrollPos.x - rcPlate.left), 532 } else {
533 point.y - (m_ptScrollPos.y - rcPlate.top)); 533 SetSingleSelect(nHitIndex);
534 } 534 }
535 535
536 CPDF_Point CFX_ListCtrl::OutToIn(const CPDF_Point & point) const 536 if (!this->IsItemVisible(nHitIndex))
537 { 537 this->ScrollToListItem(nHitIndex);
538 CPDF_Rect rcPlate = GetPlateRect(); 538 }
539 539
540 return CPDF_Point(point.x + (m_ptScrollPos.x - rcPlate.left), 540 void CFX_ListCtrl::OnVK(FX_INT32 nItemIndex, FX_BOOL bShift, FX_BOOL bCtrl) {
541 point.y + (m_ptScrollPos.y - rcPlate.top)); 541 if (IsMultipleSel()) {
542 } 542 if (nItemIndex >= 0 && nItemIndex < GetCount()) {
543 543 if (bCtrl) {
544 CPDF_Rect CFX_ListCtrl::InToOut(const CPDF_Rect & rect) const 544 } else if (bShift) {
545 { 545 m_aSelItems.DeselectAll();
546 CPDF_Point ptLeftBottom = InToOut(CPDF_Point(rect.left,rect.bottom)); 546 m_aSelItems.Add(m_nFootIndex, nItemIndex);
547 CPDF_Point ptRightTop = InToOut(CPDF_Point(rect.right,rect.top)); 547 SelectItems();
548 548 } else {
549 return CPDF_Rect(ptLeftBottom.x,ptLeftBottom.y,ptRightTop.x,ptRightTop.y ); 549 m_aSelItems.DeselectAll();
550 } 550 m_aSelItems.Add(nItemIndex);
551 551 SelectItems();
552 CPDF_Rect CFX_ListCtrl::OutToIn(const CPDF_Rect & rect) const 552 m_nFootIndex = nItemIndex;
553 { 553 }
554 CPDF_Point ptLeftBottom = OutToIn(CPDF_Point(rect.left,rect.bottom)); 554
555 CPDF_Point ptRightTop = OutToIn(CPDF_Point(rect.right,rect.top)); 555 SetCaret(nItemIndex);
556 556 }
557 return CPDF_Rect(ptLeftBottom.x,ptLeftBottom.y,ptRightTop.x,ptRightTop.y ); 557 } else {
558 } 558 SetSingleSelect(nItemIndex);
559 559 }
560 void CFX_ListCtrl::OnMouseDown(const CPDF_Point & point,FX_BOOL bShift,FX_BOOL b Ctrl) 560
561 { 561 if (!this->IsItemVisible(nItemIndex))
562 FX_INT32 nHitIndex = this->GetItemIndex(point); 562 this->ScrollToListItem(nItemIndex);
563 563 }
564 if (IsMultipleSel()) 564
565 { 565 void CFX_ListCtrl::OnVK_UP(FX_BOOL bShift, FX_BOOL bCtrl) {
566 if (bCtrl) 566 OnVK(IsMultipleSel() ? GetCaret() - 1 : GetSelect() - 1, bShift, bCtrl);
567 { 567 }
568 if (IsItemSelected(nHitIndex)) 568
569 { 569 void CFX_ListCtrl::OnVK_DOWN(FX_BOOL bShift, FX_BOOL bCtrl) {
570 m_aSelItems.Sub(nHitIndex); 570 OnVK(IsMultipleSel() ? GetCaret() + 1 : GetSelect() + 1, bShift, bCtrl);
571 SelectItems(); 571 }
572 m_bCtrlSel = FALSE; 572
573 } 573 void CFX_ListCtrl::OnVK_LEFT(FX_BOOL bShift, FX_BOOL bCtrl) {
574 else 574 OnVK(0, bShift, bCtrl);
575 { 575 }
576 m_aSelItems.Add(nHitIndex); 576
577 SelectItems(); 577 void CFX_ListCtrl::OnVK_RIGHT(FX_BOOL bShift, FX_BOOL bCtrl) {
578 m_bCtrlSel = TRUE; 578 OnVK(GetCount() - 1, bShift, bCtrl);
579 } 579 }
580 580
581 m_nFootIndex = nHitIndex; 581 void CFX_ListCtrl::OnVK_HOME(FX_BOOL bShift, FX_BOOL bCtrl) {
582 } 582 OnVK(0, bShift, bCtrl);
583 else if (bShift) 583 }
584 { 584
585 m_aSelItems.DeselectAll(); 585 void CFX_ListCtrl::OnVK_END(FX_BOOL bShift, FX_BOOL bCtrl) {
586 m_aSelItems.Add(m_nFootIndex,nHitIndex); 586 OnVK(GetCount() - 1, bShift, bCtrl);
587 SelectItems(); 587 }
588 } 588
589 else 589 FX_BOOL CFX_ListCtrl::OnChar(FX_WORD nChar, FX_BOOL bShift, FX_BOOL bCtrl) {
590 { 590 FX_INT32 nIndex = GetLastSelected();
591 m_aSelItems.DeselectAll(); 591 FX_INT32 nFindIndex = FindNext(nIndex, nChar);
592 m_aSelItems.Add(nHitIndex); 592
593 SelectItems(); 593 if (nFindIndex != nIndex) {
594 594 OnVK(nFindIndex, bShift, bCtrl);
595 m_nFootIndex = nHitIndex; 595 return TRUE;
596 } 596 }
597 597 return FALSE;
598 SetCaret(nHitIndex);
599 }
600 else
601 {
602 SetSingleSelect(nHitIndex);
603 }
604
605 if (!this->IsItemVisible(nHitIndex))
606 this->ScrollToListItem(nHitIndex);
607 }
608
609 void CFX_ListCtrl::OnMouseMove(const CPDF_Point & point,FX_BOOL bShift,FX_BOOL b Ctrl)
610 {
611 FX_INT32 nHitIndex = this->GetItemIndex(point);
612
613 if (IsMultipleSel())
614 {
615 if (bCtrl)
616 {
617 if (m_bCtrlSel)
618 m_aSelItems.Add(m_nFootIndex,nHitIndex);
619 else
620 m_aSelItems.Sub(m_nFootIndex,nHitIndex);
621
622 SelectItems();
623 }
624 else
625 {
626 m_aSelItems.DeselectAll();
627 m_aSelItems.Add(m_nFootIndex,nHitIndex);
628 SelectItems();
629 }
630
631 SetCaret(nHitIndex);
632 }
633 else
634 {
635 SetSingleSelect(nHitIndex);
636 }
637
638 if (!this->IsItemVisible(nHitIndex))
639 this->ScrollToListItem(nHitIndex);
640 }
641
642 void CFX_ListCtrl::OnVK(FX_INT32 nItemIndex,FX_BOOL bShift,FX_BOOL bCtrl)
643 {
644 if (IsMultipleSel())
645 {
646 if (nItemIndex >= 0 && nItemIndex < GetCount())
647 {
648 if (bCtrl)
649 {
650 }
651 else if (bShift)
652 {
653 m_aSelItems.DeselectAll();
654 m_aSelItems.Add(m_nFootIndex,nItemIndex);
655 SelectItems();
656 }
657 else
658 {
659 m_aSelItems.DeselectAll();
660 m_aSelItems.Add(nItemIndex);
661 SelectItems();
662 m_nFootIndex = nItemIndex;
663 }
664
665 SetCaret(nItemIndex);
666 }
667 }
668 else
669 {
670 SetSingleSelect(nItemIndex);
671 }
672
673 if (!this->IsItemVisible(nItemIndex))
674 this->ScrollToListItem(nItemIndex);
675 }
676
677 void CFX_ListCtrl::OnVK_UP(FX_BOOL bShift,FX_BOOL bCtrl)
678 {
679 OnVK(IsMultipleSel() ? GetCaret()-1 : GetSelect()-1, bShift, bCtrl);
680 }
681
682 void CFX_ListCtrl::OnVK_DOWN(FX_BOOL bShift,FX_BOOL bCtrl)
683 {
684 OnVK(IsMultipleSel() ? GetCaret()+1 : GetSelect()+1, bShift, bCtrl);
685 }
686
687 void CFX_ListCtrl::OnVK_LEFT(FX_BOOL bShift,FX_BOOL bCtrl)
688 {
689 OnVK(0, bShift, bCtrl);
690 }
691
692 void CFX_ListCtrl::OnVK_RIGHT(FX_BOOL bShift,FX_BOOL bCtrl)
693 {
694 OnVK(GetCount()-1, bShift, bCtrl);
695 }
696
697 void CFX_ListCtrl::OnVK_HOME(FX_BOOL bShift,FX_BOOL bCtrl)
698 {
699 OnVK(0, bShift, bCtrl);
700 }
701
702 void CFX_ListCtrl::OnVK_END(FX_BOOL bShift,FX_BOOL bCtrl)
703 {
704 OnVK(GetCount()-1, bShift, bCtrl);
705 }
706
707 FX_BOOL CFX_ListCtrl::OnChar(FX_WORD nChar,FX_BOOL bShift,FX_BOOL bCtrl)
708 {
709 FX_INT32 nIndex = GetLastSelected();
710 FX_INT32 nFindIndex = FindNext(nIndex,nChar);
711
712 if (nFindIndex != nIndex)
713 {
714 OnVK(nFindIndex, bShift, bCtrl);
715 return TRUE;
716 }
717 return FALSE;
718 } 598 }
719 599
720 /* -------- inner methods ------- */ 600 /* -------- inner methods ------- */
721 601
722 void CFX_ListCtrl::SetPlateRect(const CPDF_Rect & rect) 602 void CFX_ListCtrl::SetPlateRect(const CPDF_Rect& rect) {
723 { 603 CFX_ListContainer::SetPlateRect(rect);
724 CFX_ListContainer::SetPlateRect(rect); 604 m_ptScrollPos.x = rect.left;
725 m_ptScrollPos.x = rect.left; 605 SetScrollPos(CPDF_Point(rect.left, rect.top));
726 SetScrollPos(CPDF_Point(rect.left,rect.top)); 606 ReArrange(0);
727 ReArrange(0); 607 InvalidateItem(-1);
728 InvalidateItem(-1); 608 }
729 } 609
730 610 CPDF_Rect CFX_ListCtrl::GetItemRect(FX_INT32 nIndex) const {
731 CPDF_Rect CFX_ListCtrl::GetItemRect(FX_INT32 nIndex) const 611 return InToOut(CFX_List::GetItemRect(nIndex));
732 { 612 }
733 return InToOut(CFX_List::GetItemRect(nIndex)); 613
734 } 614 void CFX_ListCtrl::AddString(FX_LPCWSTR string) {
735 615 AddItem(string);
736 void CFX_ListCtrl::AddString(FX_LPCWSTR string) 616 ReArrange(GetCount() - 1);
737 { 617 }
738 AddItem(string); 618
739 ReArrange(GetCount() - 1); 619 void CFX_ListCtrl::SetMultipleSelect(FX_INT32 nItemIndex, FX_BOOL bSelected) {
740 } 620 if (!IsValid(nItemIndex))
741 621 return;
742 void CFX_ListCtrl::SetMultipleSelect(FX_INT32 nItemIndex, FX_BOOL bSelected) 622
743 { 623 if (bSelected != this->IsItemSelected(nItemIndex)) {
744 if (!IsValid(nItemIndex)) return; 624 if (bSelected) {
745 625 SetItemSelect(nItemIndex, TRUE);
746 if (bSelected != this->IsItemSelected(nItemIndex)) 626 InvalidateItem(nItemIndex);
747 { 627 } else {
748 if (bSelected) 628 SetItemSelect(nItemIndex, FALSE);
749 { 629 InvalidateItem(nItemIndex);
750 SetItemSelect(nItemIndex,TRUE); 630 }
751 InvalidateItem(nItemIndex); 631 }
752 } 632 }
753 else 633
754 { 634 void CFX_ListCtrl::SetSingleSelect(FX_INT32 nItemIndex) {
755 SetItemSelect(nItemIndex,FALSE); 635 if (!IsValid(nItemIndex))
756 InvalidateItem(nItemIndex); 636 return;
757 } 637
758 } 638 if (m_nSelItem != nItemIndex) {
759 } 639 if (m_nSelItem >= 0) {
760 640 SetItemSelect(m_nSelItem, FALSE);
761 void CFX_ListCtrl::SetSingleSelect(FX_INT32 nItemIndex) 641 InvalidateItem(m_nSelItem);
762 { 642 }
763 if (!IsValid(nItemIndex)) return; 643
764 644 SetItemSelect(nItemIndex, TRUE);
765 if (m_nSelItem != nItemIndex) 645 InvalidateItem(nItemIndex);
766 { 646 m_nSelItem = nItemIndex;
767 if (m_nSelItem >= 0) 647 }
768 { 648 }
769 SetItemSelect(m_nSelItem,FALSE); 649
770 InvalidateItem(m_nSelItem); 650 void CFX_ListCtrl::SetCaret(FX_INT32 nItemIndex) {
771 } 651 if (!IsValid(nItemIndex))
772 652 return;
773 SetItemSelect(nItemIndex,TRUE); 653
774 InvalidateItem(nItemIndex); 654 if (this->IsMultipleSel()) {
775 m_nSelItem = nItemIndex; 655 FX_INT32 nOldIndex = m_nCaretIndex;
776 } 656
777 } 657 if (nOldIndex != nItemIndex) {
778 658 m_nCaretIndex = nItemIndex;
779 void CFX_ListCtrl::SetCaret(FX_INT32 nItemIndex) 659
780 { 660 SetItemCaret(nOldIndex, FALSE);
781 if (!IsValid(nItemIndex)) return; 661 SetItemCaret(nItemIndex, TRUE);
782 662
783 if (this->IsMultipleSel()) 663 InvalidateItem(nOldIndex);
784 { 664 InvalidateItem(nItemIndex);
785 FX_INT32 nOldIndex = m_nCaretIndex; 665 }
786 666 }
787 if (nOldIndex != nItemIndex) 667 }
788 { 668
789 m_nCaretIndex = nItemIndex; 669 void CFX_ListCtrl::InvalidateItem(FX_INT32 nItemIndex) {
790 670 if (m_pNotify) {
791 SetItemCaret(nOldIndex, FALSE); 671 if (nItemIndex == -1) {
792 SetItemCaret(nItemIndex,TRUE); 672 if (!m_bNotifyFlag) {
793 673 m_bNotifyFlag = TRUE;
794 InvalidateItem(nOldIndex); 674 CPDF_Rect rcRefresh = GetPlateRect();
795 InvalidateItem(nItemIndex); 675 m_pNotify->IOnInvalidateRect(&rcRefresh);
796 } 676 m_bNotifyFlag = FALSE;
797 } 677 }
798 } 678 } else {
799 679 if (!m_bNotifyFlag) {
800 void CFX_ListCtrl::InvalidateItem(FX_INT32 nItemIndex) 680 m_bNotifyFlag = TRUE;
801 { 681 CPDF_Rect rcRefresh = GetItemRect(nItemIndex);
802 if (m_pNotify) 682 rcRefresh.left -= 1.0f;
803 { 683 rcRefresh.right += 1.0f;
804 if (nItemIndex == -1) 684 rcRefresh.bottom -= 1.0f;
805 { 685 rcRefresh.top += 1.0f;
806 if (!m_bNotifyFlag) 686
807 { 687 m_pNotify->IOnInvalidateRect(&rcRefresh);
808 m_bNotifyFlag = TRUE; 688 m_bNotifyFlag = FALSE;
809 CPDF_Rect rcRefresh = GetPlateRect(); 689 }
810 m_pNotify->IOnInvalidateRect(&rcRefresh); 690 }
811 m_bNotifyFlag = FALSE; 691 }
812 } 692 }
813 } 693
814 else 694 void CFX_ListCtrl::SelectItems() {
815 { 695 for (FX_INT32 i = 0, sz = m_aSelItems.GetCount(); i < sz; i++) {
816 if (!m_bNotifyFlag) 696 FX_INT32 nItemIndex = m_aSelItems.GetItemIndex(i);
817 { 697 FX_INT32 nState = m_aSelItems.GetState(i);
818 m_bNotifyFlag = TRUE; 698
819 CPDF_Rect rcRefresh = GetItemRect(nItemIndex); 699 switch (nState) {
820 rcRefresh.left -= 1.0f; 700 case 1:
821 rcRefresh.right += 1.0f; 701 SetMultipleSelect(nItemIndex, TRUE);
822 rcRefresh.bottom -= 1.0f; 702 break;
823 rcRefresh.top += 1.0f; 703 case -1:
824 704 SetMultipleSelect(nItemIndex, FALSE);
825 m_pNotify->IOnInvalidateRect(&rcRefresh); 705 break;
826 m_bNotifyFlag = FALSE; 706 }
827 } 707 }
828 } 708
829 } 709 m_aSelItems.Done();
830 } 710 }
831 711
832 void CFX_ListCtrl::SelectItems() 712 void CFX_ListCtrl::Select(FX_INT32 nItemIndex) {
833 { 713 if (!IsValid(nItemIndex))
834 for (FX_INT32 i=0,sz=m_aSelItems.GetCount(); i<sz; i++) 714 return;
835 { 715
836 FX_INT32 nItemIndex = m_aSelItems.GetItemIndex(i); 716 if (this->IsMultipleSel()) {
837 FX_INT32 nState = m_aSelItems.GetState(i); 717 m_aSelItems.Add(nItemIndex);
838 718 SelectItems();
839 switch(nState) 719 } else
840 { 720 SetSingleSelect(nItemIndex);
841 case 1: 721 }
842 SetMultipleSelect(nItemIndex, TRUE); 722
843 break; 723 FX_BOOL CFX_ListCtrl::IsItemVisible(FX_INT32 nItemIndex) const {
844 case -1: 724 CPDF_Rect rcPlate = this->GetPlateRect();
845 SetMultipleSelect(nItemIndex, FALSE); 725 CPDF_Rect rcItem = this->GetItemRect(nItemIndex);
846 break; 726
847 } 727 return rcItem.bottom >= rcPlate.bottom && rcItem.top <= rcPlate.top;
848 } 728 }
849 729
850 m_aSelItems.Done(); 730 void CFX_ListCtrl::ScrollToListItem(FX_INT32 nItemIndex) {
851 } 731 if (!IsValid(nItemIndex))
852 732 return;
853 void CFX_ListCtrl::Select(FX_INT32 nItemIndex) 733
854 { 734 CPDF_Rect rcPlate = this->GetPlateRect();
855 if (!IsValid(nItemIndex)) return; 735 CPDF_Rect rcItem = CFX_List::GetItemRect(nItemIndex);
856 736 CPDF_Rect rcItemCtrl = GetItemRect(nItemIndex);
857 if (this->IsMultipleSel()) 737
858 { 738 if (FX_EDIT_IsFloatSmaller(rcItemCtrl.bottom, rcPlate.bottom)) {
859 m_aSelItems.Add(nItemIndex); 739 if (FX_EDIT_IsFloatSmaller(rcItemCtrl.top, rcPlate.top)) {
860 SelectItems(); 740 SetScrollPosY(rcItem.bottom + rcPlate.Height());
861 } 741 }
862 else 742 } else if (FX_EDIT_IsFloatBigger(rcItemCtrl.top, rcPlate.top)) {
863 SetSingleSelect(nItemIndex); 743 if (FX_EDIT_IsFloatBigger(rcItemCtrl.bottom, rcPlate.bottom)) {
864 } 744 SetScrollPosY(rcItem.top);
865 745 }
866 FX_BOOL CFX_ListCtrl::IsItemVisible(FX_INT32 nItemIndex) const 746 }
867 { 747 }
868 CPDF_Rect rcPlate = this->GetPlateRect(); 748
869 CPDF_Rect rcItem = this->GetItemRect(nItemIndex); 749 void CFX_ListCtrl::SetScrollInfo() {
870 750 if (m_pNotify) {
871 return rcItem.bottom >= rcPlate.bottom && rcItem.top <= rcPlate.top; 751 CPDF_Rect rcPlate = GetPlateRect();
872 } 752 CPDF_Rect rcContent = CFX_List::GetContentRect();
873 753
874 void CFX_ListCtrl::ScrollToListItem(FX_INT32 nItemIndex) 754 if (!m_bNotifyFlag) {
875 { 755 m_bNotifyFlag = TRUE;
876 if (!IsValid(nItemIndex)) return; 756 m_pNotify->IOnSetScrollInfoY(rcPlate.bottom,
877 757 rcPlate.top,
878 CPDF_Rect rcPlate = this->GetPlateRect(); 758 rcContent.bottom,
879 CPDF_Rect rcItem = CFX_List::GetItemRect(nItemIndex); 759 rcContent.top,
880 CPDF_Rect rcItemCtrl = GetItemRect(nItemIndex); 760 GetFirstHeight(),
881 761 rcPlate.Height());
882 if (FX_EDIT_IsFloatSmaller(rcItemCtrl.bottom, rcPlate.bottom)) 762 m_bNotifyFlag = FALSE;
883 { 763 }
884 if (FX_EDIT_IsFloatSmaller(rcItemCtrl.top, rcPlate.top)) 764 }
885 { 765 }
886 SetScrollPosY(rcItem.bottom + rcPlate.Height()); 766
887 } 767 void CFX_ListCtrl::SetScrollPos(const CPDF_Point& point) {
888 } 768 SetScrollPosY(point.y);
889 else if (FX_EDIT_IsFloatBigger(rcItemCtrl.top, rcPlate.top)) 769 }
890 { 770
891 if (FX_EDIT_IsFloatBigger(rcItemCtrl.bottom, rcPlate.bottom)) 771 void CFX_ListCtrl::SetScrollPosY(FX_FLOAT fy) {
892 { 772 if (!FX_EDIT_IsFloatEqual(m_ptScrollPos.y, fy)) {
893 SetScrollPosY(rcItem.top); 773 CPDF_Rect rcPlate = this->GetPlateRect();
894 } 774 CPDF_Rect rcContent = CFX_List::GetContentRect();
895 } 775
896 } 776 if (rcPlate.Height() > rcContent.Height()) {
897 777 fy = rcPlate.top;
898 void CFX_ListCtrl::SetScrollInfo() 778 } else {
899 { 779 if (FX_EDIT_IsFloatSmaller(fy - rcPlate.Height(), rcContent.bottom)) {
900 if (m_pNotify) 780 fy = rcContent.bottom + rcPlate.Height();
901 { 781 } else if (FX_EDIT_IsFloatBigger(fy, rcContent.top)) {
902 CPDF_Rect rcPlate = GetPlateRect(); 782 fy = rcContent.top;
903 CPDF_Rect rcContent = CFX_List::GetContentRect(); 783 }
904 784 }
905 if (!m_bNotifyFlag) 785
906 { 786 m_ptScrollPos.y = fy;
907 m_bNotifyFlag = TRUE; 787 InvalidateItem(-1);
908 m_pNotify->IOnSetScrollInfoY(rcPlate.bottom, rcPlate.top , 788
909 rcContent.bottom, rcContent.top, GetFirs tHeight(), rcPlate.Height()); 789 if (m_pNotify) {
910 m_bNotifyFlag = FALSE; 790 if (!m_bNotifyFlag) {
911 } 791 m_bNotifyFlag = TRUE;
912 } 792 m_pNotify->IOnSetScrollPosY(fy);
913 } 793 m_bNotifyFlag = FALSE;
914 794 }
915 void CFX_ListCtrl::SetScrollPos(const CPDF_Point & point) 795 }
916 { 796 }
917 SetScrollPosY(point.y); 797 }
918 } 798
919 799 CPDF_Rect CFX_ListCtrl::GetContentRect() const {
920 void CFX_ListCtrl::SetScrollPosY(FX_FLOAT fy) 800 return InToOut(CFX_List::GetContentRect());
921 { 801 }
922 if (!FX_EDIT_IsFloatEqual(m_ptScrollPos.y,fy)) 802
923 { 803 void CFX_ListCtrl::ReArrange(FX_INT32 nItemIndex) {
924 CPDF_Rect rcPlate = this->GetPlateRect(); 804 CFX_List::ReArrange(nItemIndex);
925 CPDF_Rect rcContent = CFX_List::GetContentRect(); 805 SetScrollInfo();
926 806 }
927 if (rcPlate.Height() > rcContent.Height()) 807
928 { 808 void CFX_ListCtrl::SetTopItem(FX_INT32 nIndex) {
929 fy = rcPlate.top; 809 if (IsValid(nIndex)) {
930 } 810 this->GetPlateRect();
931 else 811 CPDF_Rect rcItem = CFX_List::GetItemRect(nIndex);
932 { 812 SetScrollPosY(rcItem.top);
933 if (FX_EDIT_IsFloatSmaller(fy - rcPlate.Height(), rcCont ent.bottom)) 813 }
934 { 814 }
935 fy = rcContent.bottom + rcPlate.Height(); 815
936 } 816 FX_INT32 CFX_ListCtrl::GetTopItem() const {
937 else if (FX_EDIT_IsFloatBigger(fy, rcContent.top)) 817 FX_INT32 nItemIndex = this->GetItemIndex(this->GetBTPoint());
938 { 818
939 fy = rcContent.top; 819 if (!IsItemVisible(nItemIndex) && IsItemVisible(nItemIndex + 1))
940 } 820 nItemIndex += 1;
941 } 821
942 822 return nItemIndex;
943 m_ptScrollPos.y = fy; 823 }
944 InvalidateItem(-1); 824
945 825 void CFX_ListCtrl::Empty() {
946 if (m_pNotify) 826 CFX_List::Empty();
947 { 827 InvalidateItem(-1);
948 if (!m_bNotifyFlag) 828 }
949 { 829
950 m_bNotifyFlag = TRUE; 830 void CFX_ListCtrl::Cancel() {
951 m_pNotify->IOnSetScrollPosY(fy); 831 m_aSelItems.DeselectAll();
952 m_bNotifyFlag = FALSE; 832 }
953 } 833
954 } 834 FX_INT32 CFX_ListCtrl::GetItemIndex(const CPDF_Point& point) const {
955 } 835 return CFX_List::GetItemIndex(OutToIn(point));
956 } 836 }
957 837
958 CPDF_Rect CFX_ListCtrl::GetContentRect() const 838 CFX_WideString CFX_ListCtrl::GetText() const {
959 { 839 if (this->IsMultipleSel())
960 return InToOut(CFX_List::GetContentRect()); 840 return this->GetItemText(this->m_nCaretIndex);
961 } 841 else
962 842 return this->GetItemText(this->m_nSelItem);
963 void CFX_ListCtrl::ReArrange(FX_INT32 nItemIndex) 843 }
964 {
965 CFX_List::ReArrange(nItemIndex);
966 SetScrollInfo();
967 }
968
969 void CFX_ListCtrl::SetTopItem(FX_INT32 nIndex)
970 {
971 if (IsValid(nIndex))
972 {
973 this->GetPlateRect();
974 CPDF_Rect rcItem = CFX_List::GetItemRect(nIndex);
975 SetScrollPosY(rcItem.top);
976 }
977 }
978
979 FX_INT32 CFX_ListCtrl::GetTopItem() const
980 {
981 FX_INT32 nItemIndex = this->GetItemIndex(this->GetBTPoint());
982
983 if (!IsItemVisible(nItemIndex) && IsItemVisible(nItemIndex + 1))
984 nItemIndex += 1;
985
986 return nItemIndex;
987 }
988
989 void CFX_ListCtrl::Empty()
990 {
991 CFX_List::Empty();
992 InvalidateItem(-1);
993 }
994
995 void CFX_ListCtrl::Cancel()
996 {
997 m_aSelItems.DeselectAll();
998 }
999
1000 FX_INT32 CFX_ListCtrl::GetItemIndex(const CPDF_Point & point) const
1001 {
1002 return CFX_List::GetItemIndex(OutToIn(point));
1003 }
1004
1005 CFX_WideString CFX_ListCtrl::GetText() const
1006 {
1007 if (this->IsMultipleSel())
1008 return this->GetItemText(this->m_nCaretIndex);
1009 else
1010 return this->GetItemText(this->m_nSelItem);
1011 }
1012
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698