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

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

Issue 1265503005: clang-format all pdfium code. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: sigh Created 5 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(const FX_WCHAR* 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(const FX_WCHAR* 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()
109 return word.Word; 109 : m_fFontSize(0.0f), m_pFontMap(NULL), m_bMultiple(FALSE) {}
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 (int32_t 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(const FX_WCHAR* str) {
131 void CFX_List::Empty() 131 if (CFX_ListItem* pListItem = new CFX_ListItem()) {
132 { 132 pListItem->SetFontMap(m_pFontMap);
133 for (int32_t 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(int32_t 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 (int32_t 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(const FX_WCHAR* 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(int32_t nIndex) const {
157 } 157 if (CFX_ListItem* pListItem = m_aListItems.GetAt(nIndex)) {
158 } 158 return pListItem->GetEdit();
159 159 }
160 void CFX_List::ReArrange(int32_t 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 int32_t CFX_List::GetCount() const {
165 fPosY = pPrevItem->GetRect().bottom; 165 return m_aListItems.GetSize();
166 166 }
167 for (int32_t 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(int32_t nIndex) const 180 int32_t 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 (int32_t 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 int32_t 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 int32_t 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 (int32_t 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 int32_t CFX_List::GetFirstSelected() const {
221 CLST_Rect rcListItem = pListItem->GetRect(); 221 for (int32_t 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 int32_t CFX_List::GetLastSelected() const {
231 } 231 for (int32_t 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 int32_t CFX_List::FindNext(int32_t nIndex, FX_WCHAR nChar) const {
247 { 247 int32_t nCircleIndex = nIndex;
248 if (CFX_ListItem * pListItem = m_aListItems.GetAt(0)) 248
249 { 249 for (int32_t 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 int32_t CFX_List::GetFirstSelected() const 256 return nCircleIndex;
257 { 257 }
258 for (int32_t 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(int32_t 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 int32_t CFX_List::GetLastSelected() const 269 }
270 { 270
271 for (int32_t 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(int32_t 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(int32_t 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(int32_t nItemIndex, FX_BOOL bCaret) {
289 int32_t CFX_List::FindNext(int32_t nIndex,FX_WCHAR nChar) const 289 if (CFX_ListItem* pListItem = m_aListItems.GetAt(nItemIndex)) {
290 { 290 pListItem->SetCaret(bCaret);
291 int32_t nCircleIndex = nIndex; 291 }
292 292 }
293 for (int32_t 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(int32_t nItemIndex) const {
303 } 303 return nItemIndex >= 0 && nItemIndex < m_aListItems.GetSize();
304 304 }
305 return nCircleIndex; 305
306 } 306 CFX_WideString CFX_List::GetItemText(int32_t nIndex) const {
307 307 if (CFX_ListItem* pListItem = m_aListItems.GetAt(nIndex)) {
308 CPDF_Rect CFX_List::GetItemRect(int32_t 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 CPLST_Select::~CPLST_Select() {
320 320 for (int32_t i = 0, sz = m_aItems.GetSize(); i < sz; i++)
321 FX_BOOL CFX_List::IsItemSelected(int32_t nIndex) const 321 delete m_aItems.GetAt(i);
322 { 322
323 if (CFX_ListItem * pListItem = m_aListItems.GetAt(nIndex)) 323 m_aItems.RemoveAll();
324 { 324 }
325 return pListItem->IsSelected(); 325
326 } 326 void CPLST_Select::Add(int32_t nItemIndex) {
327 327 int32_t nIndex = Find(nItemIndex);
328 return FALSE; 328
329 } 329 if (nIndex < 0)
330 330 m_aItems.Add(new CPLST_Select_Item(nItemIndex, 1));
331 void CFX_List::SetItemSelect(int32_t nItemIndex, FX_BOOL bSelected) 331 else {
332 { 332 if (CPLST_Select_Item* pItem = m_aItems.GetAt(nIndex)) {
333 if (CFX_ListItem * pListItem = m_aListItems.GetAt(nItemIndex)) 333 pItem->nState = 1;
334 { 334 }
335 pListItem->SetSelect(bSelected); 335 }
336 } 336 }
337 } 337
338 338 void CPLST_Select::Add(int32_t nBeginIndex, int32_t nEndIndex) {
339 void CFX_List::SetItemCaret(int32_t nItemIndex, FX_BOOL bCaret) 339 if (nBeginIndex > nEndIndex) {
340 { 340 int32_t nTemp = nEndIndex;
341 if (CFX_ListItem * pListItem = m_aListItems.GetAt(nItemIndex)) 341 nEndIndex = nBeginIndex;
342 { 342 nBeginIndex = nTemp;
343 pListItem->SetCaret(bCaret); 343 }
344 } 344
345 } 345 for (int32_t i = nBeginIndex; i <= nEndIndex; i++)
346 346 Add(i);
347 void CFX_List::SetMultipleSel(FX_BOOL bMultiple) 347 }
348 { 348
349 m_bMultiple = bMultiple; 349 void CPLST_Select::Sub(int32_t nItemIndex) {
350 } 350 for (int32_t i = m_aItems.GetSize() - 1; i >= 0; i--) {
351 351 if (CPLST_Select_Item* pItem = m_aItems.GetAt(i))
352 FX_BOOL CFX_List::IsMultipleSel() const 352 if (pItem->nItemIndex == nItemIndex)
353 { 353 pItem->nState = -1;
354 return m_bMultiple; 354 }
355 } 355 }
356 356
357 FX_BOOL CFX_List::IsValid(int32_t nItemIndex) const 357 void CPLST_Select::Sub(int32_t nBeginIndex, int32_t nEndIndex) {
358 { 358 if (nBeginIndex > nEndIndex) {
359 return nItemIndex >= 0 && nItemIndex < m_aListItems.GetSize(); 359 int32_t nTemp = nEndIndex;
360 } 360 nEndIndex = nBeginIndex;
361 361 nBeginIndex = nTemp;
362 CFX_WideString CFX_List::GetItemText(int32_t nIndex) const 362 }
363 { 363
364 if (CFX_ListItem * pListItem = m_aListItems.GetAt(nIndex)) 364 for (int32_t i = nBeginIndex; i <= nEndIndex; i++)
365 { 365 Sub(i);
366 return pListItem->GetText(); 366 }
367 } 367
368 368 int32_t CPLST_Select::Find(int32_t nItemIndex) const {
369 return L""; 369 for (int32_t i = 0, sz = m_aItems.GetSize(); i < sz; i++) {
370 } 370 if (CPLST_Select_Item* pItem = m_aItems.GetAt(i)) {
371 371 if (pItem->nItemIndex == nItemIndex)
372 /* ------------------------------------ CPLST_Select --------------------------- ------- */ 372 return i;
373 373 }
374 CPLST_Select::CPLST_Select() 374 }
375 { 375
376 } 376 return -1;
377 377 }
378 CPLST_Select::~CPLST_Select() 378
379 { 379 FX_BOOL CPLST_Select::IsExist(int32_t nItemIndex) const {
380 for (int32_t i=0,sz=m_aItems.GetSize(); i<sz; i++) 380 return Find(nItemIndex) >= 0;
381 delete m_aItems.GetAt(i); 381 }
382 382
383 m_aItems.RemoveAll(); 383 int32_t CPLST_Select::GetCount() const {
384 } 384 return m_aItems.GetSize();
385 385 }
386 void CPLST_Select::Add(int32_t nItemIndex) 386
387 { 387 int32_t CPLST_Select::GetItemIndex(int32_t nIndex) const {
388 int32_t nIndex = Find(nItemIndex); 388 if (nIndex >= 0 && nIndex < m_aItems.GetSize())
389 389 if (CPLST_Select_Item* pItem = m_aItems.GetAt(nIndex))
390 if (nIndex < 0) 390 return pItem->nItemIndex;
391 m_aItems.Add(new CPLST_Select_Item(nItemIndex,1)); 391
392 else 392 return -1;
393 { 393 }
394 if (CPLST_Select_Item * pItem = m_aItems.GetAt(nIndex)) 394
395 { 395 int32_t CPLST_Select::GetState(int32_t nIndex) const {
396 pItem->nState = 1; 396 if (nIndex >= 0 && nIndex < m_aItems.GetSize())
397 } 397 if (CPLST_Select_Item* pItem = m_aItems.GetAt(nIndex))
398 } 398 return pItem->nState;
399 } 399
400 400 return 0;
401 void CPLST_Select::Add(int32_t nBeginIndex, int32_t nEndIndex) 401 }
402 { 402
403 if (nBeginIndex > nEndIndex) 403 void CPLST_Select::DeselectAll() {
404 { 404 for (int32_t i = 0, sz = m_aItems.GetSize(); i < sz; i++) {
405 int32_t nTemp = nEndIndex; 405 if (CPLST_Select_Item* pItem = m_aItems.GetAt(i)) {
406 nEndIndex = nBeginIndex; 406 pItem->nState = -1;
407 nBeginIndex = nTemp; 407 }
408 } 408 }
409 409 }
410 for (int32_t i=nBeginIndex; i<=nEndIndex; i++) Add(i); 410
411 } 411 void CPLST_Select::Done() {
412 412 for (int32_t i = m_aItems.GetSize() - 1; i >= 0; i--) {
413 void CPLST_Select::Sub(int32_t nItemIndex) 413 if (CPLST_Select_Item* pItem = m_aItems.GetAt(i)) {
414 { 414 if (pItem->nState == -1) {
415 for (int32_t i=m_aItems.GetSize()-1; i>=0; i--) 415 delete pItem;
416 { 416 m_aItems.RemoveAt(i);
417 if (CPLST_Select_Item * pItem = m_aItems.GetAt(i)) 417 } else {
418 if (pItem->nItemIndex == nItemIndex) 418 pItem->nState = 0;
419 pItem->nState = -1; 419 }
420 } 420 }
421 } 421 }
422 422 }
423 void CPLST_Select::Sub(int32_t nBeginIndex, int32_t nEndIndex) 423
424 { 424 /* ------------------------------------ CFX_ListCtrl
425 if (nBeginIndex > nEndIndex) 425 * --------------------------------- */
426 { 426
427 int32_t nTemp = nEndIndex; 427 CFX_ListCtrl::CFX_ListCtrl()
428 nEndIndex = nBeginIndex; 428 : m_pNotify(NULL),
429 nBeginIndex = nTemp; 429 m_bNotifyFlag(FALSE),
430 } 430 m_ptScrollPos(0.0f, 0.0f),
431 431 m_nSelItem(-1),
432 for (int32_t i=nBeginIndex; i<=nEndIndex; i++) Sub(i); 432 m_nFootIndex(-1),
433 } 433 m_bCtrlSel(FALSE),
434 434 m_nCaretIndex(-1) {}
435 int32_t CPLST_Select::Find(int32_t nItemIndex) const 435
436 { 436 CFX_ListCtrl::~CFX_ListCtrl() {}
437 for (int32_t i=0,sz=m_aItems.GetSize(); i<sz; i++) 437
438 { 438 void CFX_ListCtrl::SetNotify(IFX_List_Notify* pNotify) {
439 if (CPLST_Select_Item * pItem = m_aItems.GetAt(i)) 439 m_pNotify = pNotify;
440 { 440 }
441 if (pItem->nItemIndex == nItemIndex) 441
442 return i; 442 CPDF_Point CFX_ListCtrl::InToOut(const CPDF_Point& point) const {
443 } 443 CPDF_Rect rcPlate = GetPlateRect();
444 } 444
445 445 return CPDF_Point(point.x - (m_ptScrollPos.x - rcPlate.left),
446 return -1; 446 point.y - (m_ptScrollPos.y - rcPlate.top));
447 } 447 }
448 448
449 FX_BOOL CPLST_Select::IsExist(int32_t nItemIndex) const 449 CPDF_Point CFX_ListCtrl::OutToIn(const CPDF_Point& point) const {
450 { 450 CPDF_Rect rcPlate = GetPlateRect();
451 return Find(nItemIndex) >= 0; 451
452 } 452 return CPDF_Point(point.x + (m_ptScrollPos.x - rcPlate.left),
453 453 point.y + (m_ptScrollPos.y - rcPlate.top));
454 int32_t CPLST_Select::GetCount() const 454 }
455 { 455
456 return m_aItems.GetSize(); 456 CPDF_Rect CFX_ListCtrl::InToOut(const CPDF_Rect& rect) const {
457 } 457 CPDF_Point ptLeftBottom = InToOut(CPDF_Point(rect.left, rect.bottom));
458 458 CPDF_Point ptRightTop = InToOut(CPDF_Point(rect.right, rect.top));
459 int32_t CPLST_Select::GetItemIndex(int32_t nIndex) const 459
460 { 460 return CPDF_Rect(ptLeftBottom.x, ptLeftBottom.y, ptRightTop.x, ptRightTop.y);
461 if (nIndex >= 0 && nIndex < m_aItems.GetSize()) 461 }
462 if (CPLST_Select_Item * pItem = m_aItems.GetAt(nIndex)) 462
463 return pItem->nItemIndex; 463 CPDF_Rect CFX_ListCtrl::OutToIn(const CPDF_Rect& rect) const {
464 464 CPDF_Point ptLeftBottom = OutToIn(CPDF_Point(rect.left, rect.bottom));
465 return -1; 465 CPDF_Point ptRightTop = OutToIn(CPDF_Point(rect.right, rect.top));
466 } 466
467 467 return CPDF_Rect(ptLeftBottom.x, ptLeftBottom.y, ptRightTop.x, ptRightTop.y);
468 int32_t CPLST_Select::GetState(int32_t nIndex) const 468 }
469 { 469
470 if (nIndex >= 0 && nIndex < m_aItems.GetSize()) 470 void CFX_ListCtrl::OnMouseDown(const CPDF_Point& point,
471 if (CPLST_Select_Item * pItem = m_aItems.GetAt(nIndex)) 471 FX_BOOL bShift,
472 return pItem->nState; 472 FX_BOOL bCtrl) {
473 473 int32_t nHitIndex = GetItemIndex(point);
474 return 0; 474
475 } 475 if (IsMultipleSel()) {
476 476 if (bCtrl) {
477 void CPLST_Select::DeselectAll() 477 if (IsItemSelected(nHitIndex)) {
478 { 478 m_aSelItems.Sub(nHitIndex);
479 for (int32_t i=0,sz=m_aItems.GetSize(); i<sz; i++) 479 SelectItems();
480 { 480 m_bCtrlSel = FALSE;
481 if (CPLST_Select_Item * pItem = m_aItems.GetAt(i)) 481 } else {
482 { 482 m_aSelItems.Add(nHitIndex);
483 pItem->nState = -1; 483 SelectItems();
484 } 484 m_bCtrlSel = TRUE;
485 } 485 }
486 } 486
487 487 m_nFootIndex = nHitIndex;
488 void CPLST_Select::Done() 488 } else if (bShift) {
489 { 489 m_aSelItems.DeselectAll();
490 for (int32_t i=m_aItems.GetSize()-1; i>=0; i--) 490 m_aSelItems.Add(m_nFootIndex, nHitIndex);
491 { 491 SelectItems();
492 if (CPLST_Select_Item * pItem = m_aItems.GetAt(i)) 492 } else {
493 { 493 m_aSelItems.DeselectAll();
494 if (pItem->nState == -1) 494 m_aSelItems.Add(nHitIndex);
495 { 495 SelectItems();
496 delete pItem; 496
497 m_aItems.RemoveAt(i); 497 m_nFootIndex = nHitIndex;
498 } 498 }
499 else 499
500 { 500 SetCaret(nHitIndex);
501 pItem->nState = 0; 501 } else {
502 } 502 SetSingleSelect(nHitIndex);
503 } 503 }
504 } 504
505 } 505 if (!IsItemVisible(nHitIndex))
506 506 ScrollToListItem(nHitIndex);
507 /* ------------------------------------ CFX_ListCtrl --------------------------- ------ */ 507 }
508 508
509 CFX_ListCtrl::CFX_ListCtrl() : m_pNotify(NULL), 509 void CFX_ListCtrl::OnMouseMove(const CPDF_Point& point,
510 m_bNotifyFlag(FALSE), 510 FX_BOOL bShift,
511 m_ptScrollPos(0.0f,0.0f), 511 FX_BOOL bCtrl) {
512 m_nSelItem(-1), 512 int32_t nHitIndex = GetItemIndex(point);
513 m_nFootIndex(-1), 513
514 m_bCtrlSel(FALSE), 514 if (IsMultipleSel()) {
515 m_nCaretIndex(-1) 515 if (bCtrl) {
516 { 516 if (m_bCtrlSel)
517 } 517 m_aSelItems.Add(m_nFootIndex, nHitIndex);
518 518 else
519 CFX_ListCtrl::~CFX_ListCtrl() 519 m_aSelItems.Sub(m_nFootIndex, nHitIndex);
520 { 520
521 } 521 SelectItems();
522 522 } else {
523 void CFX_ListCtrl::SetNotify(IFX_List_Notify * pNotify) 523 m_aSelItems.DeselectAll();
524 { 524 m_aSelItems.Add(m_nFootIndex, nHitIndex);
525 m_pNotify = pNotify; 525 SelectItems();
526 } 526 }
527 527
528 CPDF_Point CFX_ListCtrl::InToOut(const CPDF_Point & point) const 528 SetCaret(nHitIndex);
529 { 529 } else {
530 CPDF_Rect rcPlate = GetPlateRect(); 530 SetSingleSelect(nHitIndex);
531 531 }
532 return CPDF_Point(point.x - (m_ptScrollPos.x - rcPlate.left), 532
533 point.y - (m_ptScrollPos.y - rcPlate.top)); 533 if (!IsItemVisible(nHitIndex))
534 } 534 ScrollToListItem(nHitIndex);
535 535 }
536 CPDF_Point CFX_ListCtrl::OutToIn(const CPDF_Point & point) const 536
537 { 537 void CFX_ListCtrl::OnVK(int32_t nItemIndex, FX_BOOL bShift, FX_BOOL bCtrl) {
538 CPDF_Rect rcPlate = GetPlateRect(); 538 if (IsMultipleSel()) {
539 539 if (nItemIndex >= 0 && nItemIndex < GetCount()) {
540 return CPDF_Point(point.x + (m_ptScrollPos.x - rcPlate.left), 540 if (bCtrl) {
541 point.y + (m_ptScrollPos.y - rcPlate.top)); 541 } else if (bShift) {
542 } 542 m_aSelItems.DeselectAll();
543 543 m_aSelItems.Add(m_nFootIndex, nItemIndex);
544 CPDF_Rect CFX_ListCtrl::InToOut(const CPDF_Rect & rect) const 544 SelectItems();
545 { 545 } else {
546 CPDF_Point ptLeftBottom = InToOut(CPDF_Point(rect.left,rect.bottom)); 546 m_aSelItems.DeselectAll();
547 CPDF_Point ptRightTop = InToOut(CPDF_Point(rect.right,rect.top)); 547 m_aSelItems.Add(nItemIndex);
548 548 SelectItems();
549 return CPDF_Rect(ptLeftBottom.x,ptLeftBottom.y,ptRightTop.x,ptRightTop.y ); 549 m_nFootIndex = nItemIndex;
550 } 550 }
551 551
552 CPDF_Rect CFX_ListCtrl::OutToIn(const CPDF_Rect & rect) const 552 SetCaret(nItemIndex);
553 { 553 }
554 CPDF_Point ptLeftBottom = OutToIn(CPDF_Point(rect.left,rect.bottom)); 554 } else {
555 CPDF_Point ptRightTop = OutToIn(CPDF_Point(rect.right,rect.top)); 555 SetSingleSelect(nItemIndex);
556 556 }
557 return CPDF_Rect(ptLeftBottom.x,ptLeftBottom.y,ptRightTop.x,ptRightTop.y ); 557
558 } 558 if (!IsItemVisible(nItemIndex))
559 559 ScrollToListItem(nItemIndex);
560 void CFX_ListCtrl::OnMouseDown(const CPDF_Point & point,FX_BOOL bShift,FX_BOOL b Ctrl) 560 }
561 { 561
562 int32_t nHitIndex = GetItemIndex(point); 562 void CFX_ListCtrl::OnVK_UP(FX_BOOL bShift, FX_BOOL bCtrl) {
563 563 OnVK(IsMultipleSel() ? GetCaret() - 1 : GetSelect() - 1, bShift, bCtrl);
564 if (IsMultipleSel()) 564 }
565 { 565
566 if (bCtrl) 566 void CFX_ListCtrl::OnVK_DOWN(FX_BOOL bShift, FX_BOOL bCtrl) {
567 { 567 OnVK(IsMultipleSel() ? GetCaret() + 1 : GetSelect() + 1, bShift, bCtrl);
568 if (IsItemSelected(nHitIndex)) 568 }
569 { 569
570 m_aSelItems.Sub(nHitIndex); 570 void CFX_ListCtrl::OnVK_LEFT(FX_BOOL bShift, FX_BOOL bCtrl) {
571 SelectItems(); 571 OnVK(0, bShift, bCtrl);
572 m_bCtrlSel = FALSE; 572 }
573 } 573
574 else 574 void CFX_ListCtrl::OnVK_RIGHT(FX_BOOL bShift, FX_BOOL bCtrl) {
575 { 575 OnVK(GetCount() - 1, bShift, bCtrl);
576 m_aSelItems.Add(nHitIndex); 576 }
577 SelectItems(); 577
578 m_bCtrlSel = TRUE; 578 void CFX_ListCtrl::OnVK_HOME(FX_BOOL bShift, FX_BOOL bCtrl) {
579 } 579 OnVK(0, bShift, bCtrl);
580 580 }
581 m_nFootIndex = nHitIndex; 581
582 } 582 void CFX_ListCtrl::OnVK_END(FX_BOOL bShift, FX_BOOL bCtrl) {
583 else if (bShift) 583 OnVK(GetCount() - 1, bShift, bCtrl);
584 { 584 }
585 m_aSelItems.DeselectAll(); 585
586 m_aSelItems.Add(m_nFootIndex,nHitIndex); 586 FX_BOOL CFX_ListCtrl::OnChar(FX_WORD nChar, FX_BOOL bShift, FX_BOOL bCtrl) {
587 SelectItems(); 587 int32_t nIndex = GetLastSelected();
588 } 588 int32_t nFindIndex = FindNext(nIndex, nChar);
589 else 589
590 { 590 if (nFindIndex != nIndex) {
591 m_aSelItems.DeselectAll(); 591 OnVK(nFindIndex, bShift, bCtrl);
592 m_aSelItems.Add(nHitIndex); 592 return TRUE;
593 SelectItems(); 593 }
594 594 return FALSE;
595 m_nFootIndex = nHitIndex;
596 }
597
598 SetCaret(nHitIndex);
599 }
600 else
601 {
602 SetSingleSelect(nHitIndex);
603 }
604
605 if (!IsItemVisible(nHitIndex))
606 ScrollToListItem(nHitIndex);
607 }
608
609 void CFX_ListCtrl::OnMouseMove(const CPDF_Point & point,FX_BOOL bShift,FX_BOOL b Ctrl)
610 {
611 int32_t nHitIndex = 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 (!IsItemVisible(nHitIndex))
639 ScrollToListItem(nHitIndex);
640 }
641
642 void CFX_ListCtrl::OnVK(int32_t 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 (!IsItemVisible(nItemIndex))
674 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 int32_t nIndex = GetLastSelected();
710 int32_t nFindIndex = FindNext(nIndex,nChar);
711
712 if (nFindIndex != nIndex)
713 {
714 OnVK(nFindIndex, bShift, bCtrl);
715 return TRUE;
716 }
717 return FALSE;
718 } 595 }
719 596
720 /* -------- inner methods ------- */ 597 /* -------- inner methods ------- */
721 598
722 void CFX_ListCtrl::SetPlateRect(const CPDF_Rect & rect) 599 void CFX_ListCtrl::SetPlateRect(const CPDF_Rect& rect) {
723 { 600 CFX_ListContainer::SetPlateRect(rect);
724 CFX_ListContainer::SetPlateRect(rect); 601 m_ptScrollPos.x = rect.left;
725 m_ptScrollPos.x = rect.left; 602 SetScrollPos(CPDF_Point(rect.left, rect.top));
726 SetScrollPos(CPDF_Point(rect.left,rect.top)); 603 ReArrange(0);
727 ReArrange(0); 604 InvalidateItem(-1);
728 InvalidateItem(-1); 605 }
729 } 606
730 607 CPDF_Rect CFX_ListCtrl::GetItemRect(int32_t nIndex) const {
731 CPDF_Rect CFX_ListCtrl::GetItemRect(int32_t nIndex) const 608 return InToOut(CFX_List::GetItemRect(nIndex));
732 { 609 }
733 return InToOut(CFX_List::GetItemRect(nIndex)); 610
734 } 611 void CFX_ListCtrl::AddString(const FX_WCHAR* string) {
735 612 AddItem(string);
736 void CFX_ListCtrl::AddString(const FX_WCHAR* string) 613 ReArrange(GetCount() - 1);
737 { 614 }
738 AddItem(string); 615
739 ReArrange(GetCount() - 1); 616 void CFX_ListCtrl::SetMultipleSelect(int32_t nItemIndex, FX_BOOL bSelected) {
740 } 617 if (!IsValid(nItemIndex))
741 618 return;
742 void CFX_ListCtrl::SetMultipleSelect(int32_t nItemIndex, FX_BOOL bSelected) 619
743 { 620 if (bSelected != IsItemSelected(nItemIndex)) {
744 if (!IsValid(nItemIndex)) return; 621 if (bSelected) {
745 622 SetItemSelect(nItemIndex, TRUE);
746 if (bSelected != IsItemSelected(nItemIndex)) 623 InvalidateItem(nItemIndex);
747 { 624 } else {
748 if (bSelected) 625 SetItemSelect(nItemIndex, FALSE);
749 { 626 InvalidateItem(nItemIndex);
750 SetItemSelect(nItemIndex,TRUE); 627 }
751 InvalidateItem(nItemIndex); 628 }
752 } 629 }
753 else 630
754 { 631 void CFX_ListCtrl::SetSingleSelect(int32_t nItemIndex) {
755 SetItemSelect(nItemIndex,FALSE); 632 if (!IsValid(nItemIndex))
756 InvalidateItem(nItemIndex); 633 return;
757 } 634
758 } 635 if (m_nSelItem != nItemIndex) {
759 } 636 if (m_nSelItem >= 0) {
760 637 SetItemSelect(m_nSelItem, FALSE);
761 void CFX_ListCtrl::SetSingleSelect(int32_t nItemIndex) 638 InvalidateItem(m_nSelItem);
762 { 639 }
763 if (!IsValid(nItemIndex)) return; 640
764 641 SetItemSelect(nItemIndex, TRUE);
765 if (m_nSelItem != nItemIndex) 642 InvalidateItem(nItemIndex);
766 { 643 m_nSelItem = nItemIndex;
767 if (m_nSelItem >= 0) 644 }
768 { 645 }
769 SetItemSelect(m_nSelItem,FALSE); 646
770 InvalidateItem(m_nSelItem); 647 void CFX_ListCtrl::SetCaret(int32_t nItemIndex) {
771 } 648 if (!IsValid(nItemIndex))
772 649 return;
773 SetItemSelect(nItemIndex,TRUE); 650
774 InvalidateItem(nItemIndex); 651 if (IsMultipleSel()) {
775 m_nSelItem = nItemIndex; 652 int32_t nOldIndex = m_nCaretIndex;
776 } 653
777 } 654 if (nOldIndex != nItemIndex) {
778 655 m_nCaretIndex = nItemIndex;
779 void CFX_ListCtrl::SetCaret(int32_t nItemIndex) 656
780 { 657 SetItemCaret(nOldIndex, FALSE);
781 if (!IsValid(nItemIndex)) return; 658 SetItemCaret(nItemIndex, TRUE);
782 659
783 if (IsMultipleSel()) 660 InvalidateItem(nOldIndex);
784 { 661 InvalidateItem(nItemIndex);
785 int32_t nOldIndex = m_nCaretIndex; 662 }
786 663 }
787 if (nOldIndex != nItemIndex) 664 }
788 { 665
789 m_nCaretIndex = nItemIndex; 666 void CFX_ListCtrl::InvalidateItem(int32_t nItemIndex) {
790 667 if (m_pNotify) {
791 SetItemCaret(nOldIndex, FALSE); 668 if (nItemIndex == -1) {
792 SetItemCaret(nItemIndex,TRUE); 669 if (!m_bNotifyFlag) {
793 670 m_bNotifyFlag = TRUE;
794 InvalidateItem(nOldIndex); 671 CPDF_Rect rcRefresh = GetPlateRect();
795 InvalidateItem(nItemIndex); 672 m_pNotify->IOnInvalidateRect(&rcRefresh);
796 } 673 m_bNotifyFlag = FALSE;
797 } 674 }
798 } 675 } else {
799 676 if (!m_bNotifyFlag) {
800 void CFX_ListCtrl::InvalidateItem(int32_t nItemIndex) 677 m_bNotifyFlag = TRUE;
801 { 678 CPDF_Rect rcRefresh = GetItemRect(nItemIndex);
802 if (m_pNotify) 679 rcRefresh.left -= 1.0f;
803 { 680 rcRefresh.right += 1.0f;
804 if (nItemIndex == -1) 681 rcRefresh.bottom -= 1.0f;
805 { 682 rcRefresh.top += 1.0f;
806 if (!m_bNotifyFlag) 683
807 { 684 m_pNotify->IOnInvalidateRect(&rcRefresh);
808 m_bNotifyFlag = TRUE; 685 m_bNotifyFlag = FALSE;
809 CPDF_Rect rcRefresh = GetPlateRect(); 686 }
810 m_pNotify->IOnInvalidateRect(&rcRefresh); 687 }
811 m_bNotifyFlag = FALSE; 688 }
812 } 689 }
813 } 690
814 else 691 void CFX_ListCtrl::SelectItems() {
815 { 692 for (int32_t i = 0, sz = m_aSelItems.GetCount(); i < sz; i++) {
816 if (!m_bNotifyFlag) 693 int32_t nItemIndex = m_aSelItems.GetItemIndex(i);
817 { 694 int32_t nState = m_aSelItems.GetState(i);
818 m_bNotifyFlag = TRUE; 695
819 CPDF_Rect rcRefresh = GetItemRect(nItemIndex); 696 switch (nState) {
820 rcRefresh.left -= 1.0f; 697 case 1:
821 rcRefresh.right += 1.0f; 698 SetMultipleSelect(nItemIndex, TRUE);
822 rcRefresh.bottom -= 1.0f; 699 break;
823 rcRefresh.top += 1.0f; 700 case -1:
824 701 SetMultipleSelect(nItemIndex, FALSE);
825 m_pNotify->IOnInvalidateRect(&rcRefresh); 702 break;
826 m_bNotifyFlag = FALSE; 703 }
827 } 704 }
828 } 705
829 } 706 m_aSelItems.Done();
830 } 707 }
831 708
832 void CFX_ListCtrl::SelectItems() 709 void CFX_ListCtrl::Select(int32_t nItemIndex) {
833 { 710 if (!IsValid(nItemIndex))
834 for (int32_t i=0,sz=m_aSelItems.GetCount(); i<sz; i++) 711 return;
835 { 712
836 int32_t nItemIndex = m_aSelItems.GetItemIndex(i); 713 if (IsMultipleSel()) {
837 int32_t nState = m_aSelItems.GetState(i); 714 m_aSelItems.Add(nItemIndex);
838 715 SelectItems();
839 switch(nState) 716 } else
840 { 717 SetSingleSelect(nItemIndex);
841 case 1: 718 }
842 SetMultipleSelect(nItemIndex, TRUE); 719
843 break; 720 FX_BOOL CFX_ListCtrl::IsItemVisible(int32_t nItemIndex) const {
844 case -1: 721 CPDF_Rect rcPlate = GetPlateRect();
845 SetMultipleSelect(nItemIndex, FALSE); 722 CPDF_Rect rcItem = GetItemRect(nItemIndex);
846 break; 723
847 } 724 return rcItem.bottom >= rcPlate.bottom && rcItem.top <= rcPlate.top;
848 } 725 }
849 726
850 m_aSelItems.Done(); 727 void CFX_ListCtrl::ScrollToListItem(int32_t nItemIndex) {
851 } 728 if (!IsValid(nItemIndex))
852 729 return;
853 void CFX_ListCtrl::Select(int32_t nItemIndex) 730
854 { 731 CPDF_Rect rcPlate = GetPlateRect();
855 if (!IsValid(nItemIndex)) return; 732 CPDF_Rect rcItem = CFX_List::GetItemRect(nItemIndex);
856 733 CPDF_Rect rcItemCtrl = GetItemRect(nItemIndex);
857 if (IsMultipleSel()) 734
858 { 735 if (FX_EDIT_IsFloatSmaller(rcItemCtrl.bottom, rcPlate.bottom)) {
859 m_aSelItems.Add(nItemIndex); 736 if (FX_EDIT_IsFloatSmaller(rcItemCtrl.top, rcPlate.top)) {
860 SelectItems(); 737 SetScrollPosY(rcItem.bottom + rcPlate.Height());
861 } 738 }
862 else 739 } else if (FX_EDIT_IsFloatBigger(rcItemCtrl.top, rcPlate.top)) {
863 SetSingleSelect(nItemIndex); 740 if (FX_EDIT_IsFloatBigger(rcItemCtrl.bottom, rcPlate.bottom)) {
864 } 741 SetScrollPosY(rcItem.top);
865 742 }
866 FX_BOOL CFX_ListCtrl::IsItemVisible(int32_t nItemIndex) const 743 }
867 { 744 }
868 CPDF_Rect rcPlate = GetPlateRect(); 745
869 CPDF_Rect rcItem = GetItemRect(nItemIndex); 746 void CFX_ListCtrl::SetScrollInfo() {
870 747 if (m_pNotify) {
871 return rcItem.bottom >= rcPlate.bottom && rcItem.top <= rcPlate.top; 748 CPDF_Rect rcPlate = GetPlateRect();
872 } 749 CPDF_Rect rcContent = CFX_List::GetContentRect();
873 750
874 void CFX_ListCtrl::ScrollToListItem(int32_t nItemIndex) 751 if (!m_bNotifyFlag) {
875 { 752 m_bNotifyFlag = TRUE;
876 if (!IsValid(nItemIndex)) return; 753 m_pNotify->IOnSetScrollInfoY(rcPlate.bottom, rcPlate.top,
877 754 rcContent.bottom, rcContent.top,
878 CPDF_Rect rcPlate = GetPlateRect(); 755 GetFirstHeight(), rcPlate.Height());
879 CPDF_Rect rcItem = CFX_List::GetItemRect(nItemIndex); 756 m_bNotifyFlag = FALSE;
880 CPDF_Rect rcItemCtrl = GetItemRect(nItemIndex); 757 }
881 758 }
882 if (FX_EDIT_IsFloatSmaller(rcItemCtrl.bottom, rcPlate.bottom)) 759 }
883 { 760
884 if (FX_EDIT_IsFloatSmaller(rcItemCtrl.top, rcPlate.top)) 761 void CFX_ListCtrl::SetScrollPos(const CPDF_Point& point) {
885 { 762 SetScrollPosY(point.y);
886 SetScrollPosY(rcItem.bottom + rcPlate.Height()); 763 }
887 } 764
888 } 765 void CFX_ListCtrl::SetScrollPosY(FX_FLOAT fy) {
889 else if (FX_EDIT_IsFloatBigger(rcItemCtrl.top, rcPlate.top)) 766 if (!FX_EDIT_IsFloatEqual(m_ptScrollPos.y, fy)) {
890 { 767 CPDF_Rect rcPlate = GetPlateRect();
891 if (FX_EDIT_IsFloatBigger(rcItemCtrl.bottom, rcPlate.bottom)) 768 CPDF_Rect rcContent = CFX_List::GetContentRect();
892 { 769
893 SetScrollPosY(rcItem.top); 770 if (rcPlate.Height() > rcContent.Height()) {
894 } 771 fy = rcPlate.top;
895 } 772 } else {
896 } 773 if (FX_EDIT_IsFloatSmaller(fy - rcPlate.Height(), rcContent.bottom)) {
897 774 fy = rcContent.bottom + rcPlate.Height();
898 void CFX_ListCtrl::SetScrollInfo() 775 } else if (FX_EDIT_IsFloatBigger(fy, rcContent.top)) {
899 { 776 fy = rcContent.top;
900 if (m_pNotify) 777 }
901 { 778 }
902 CPDF_Rect rcPlate = GetPlateRect(); 779
903 CPDF_Rect rcContent = CFX_List::GetContentRect(); 780 m_ptScrollPos.y = fy;
904 781 InvalidateItem(-1);
905 if (!m_bNotifyFlag) 782
906 { 783 if (m_pNotify) {
907 m_bNotifyFlag = TRUE; 784 if (!m_bNotifyFlag) {
908 m_pNotify->IOnSetScrollInfoY(rcPlate.bottom, rcPlate.top , 785 m_bNotifyFlag = TRUE;
909 rcContent.bottom, rcContent.top, GetFirs tHeight(), rcPlate.Height()); 786 m_pNotify->IOnSetScrollPosY(fy);
910 m_bNotifyFlag = FALSE; 787 m_bNotifyFlag = FALSE;
911 } 788 }
912 } 789 }
913 } 790 }
914 791 }
915 void CFX_ListCtrl::SetScrollPos(const CPDF_Point & point) 792
916 { 793 CPDF_Rect CFX_ListCtrl::GetContentRect() const {
917 SetScrollPosY(point.y); 794 return InToOut(CFX_List::GetContentRect());
918 } 795 }
919 796
920 void CFX_ListCtrl::SetScrollPosY(FX_FLOAT fy) 797 void CFX_ListCtrl::ReArrange(int32_t nItemIndex) {
921 { 798 CFX_List::ReArrange(nItemIndex);
922 if (!FX_EDIT_IsFloatEqual(m_ptScrollPos.y,fy)) 799 SetScrollInfo();
923 { 800 }
924 CPDF_Rect rcPlate = GetPlateRect(); 801
925 CPDF_Rect rcContent = CFX_List::GetContentRect(); 802 void CFX_ListCtrl::SetTopItem(int32_t nIndex) {
926 803 if (IsValid(nIndex)) {
927 if (rcPlate.Height() > rcContent.Height()) 804 GetPlateRect();
928 { 805 CPDF_Rect rcItem = CFX_List::GetItemRect(nIndex);
929 fy = rcPlate.top; 806 SetScrollPosY(rcItem.top);
930 } 807 }
931 else 808 }
932 { 809
933 if (FX_EDIT_IsFloatSmaller(fy - rcPlate.Height(), rcCont ent.bottom)) 810 int32_t CFX_ListCtrl::GetTopItem() const {
934 { 811 int32_t nItemIndex = GetItemIndex(GetBTPoint());
935 fy = rcContent.bottom + rcPlate.Height(); 812
936 } 813 if (!IsItemVisible(nItemIndex) && IsItemVisible(nItemIndex + 1))
937 else if (FX_EDIT_IsFloatBigger(fy, rcContent.top)) 814 nItemIndex += 1;
938 { 815
939 fy = rcContent.top; 816 return nItemIndex;
940 } 817 }
941 } 818
942 819 void CFX_ListCtrl::Empty() {
943 m_ptScrollPos.y = fy; 820 CFX_List::Empty();
944 InvalidateItem(-1); 821 InvalidateItem(-1);
945 822 }
946 if (m_pNotify) 823
947 { 824 void CFX_ListCtrl::Cancel() {
948 if (!m_bNotifyFlag) 825 m_aSelItems.DeselectAll();
949 { 826 }
950 m_bNotifyFlag = TRUE; 827
951 m_pNotify->IOnSetScrollPosY(fy); 828 int32_t CFX_ListCtrl::GetItemIndex(const CPDF_Point& point) const {
952 m_bNotifyFlag = FALSE; 829 return CFX_List::GetItemIndex(OutToIn(point));
953 } 830 }
954 } 831
955 } 832 CFX_WideString CFX_ListCtrl::GetText() const {
956 } 833 if (IsMultipleSel())
957 834 return GetItemText(m_nCaretIndex);
958 CPDF_Rect CFX_ListCtrl::GetContentRect() const 835 return GetItemText(m_nSelItem);
959 { 836 }
960 return InToOut(CFX_List::GetContentRect());
961 }
962
963 void CFX_ListCtrl::ReArrange(int32_t nItemIndex)
964 {
965 CFX_List::ReArrange(nItemIndex);
966 SetScrollInfo();
967 }
968
969 void CFX_ListCtrl::SetTopItem(int32_t nIndex)
970 {
971 if (IsValid(nIndex))
972 {
973 GetPlateRect();
974 CPDF_Rect rcItem = CFX_List::GetItemRect(nIndex);
975 SetScrollPosY(rcItem.top);
976 }
977 }
978
979 int32_t CFX_ListCtrl::GetTopItem() const
980 {
981 int32_t nItemIndex = GetItemIndex(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 int32_t 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 (IsMultipleSel())
1008 return GetItemText(m_nCaretIndex);
1009 return GetItemText(m_nSelItem);
1010 }
1011
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698