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

Side by Side Diff: fpdfsdk/pdfwindow/PWL_IconList.cpp

Issue 2071953002: Remove unused code. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase to master Created 4 years, 6 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
« no previous file with comments | « fpdfsdk/pdfwindow/PWL_IconList.h ('k') | fpdfsdk/pdfwindow/PWL_Label.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "fpdfsdk/pdfwindow/PWL_IconList.h"
8
9 #include "fpdfsdk/pdfwindow/PWL_Label.h"
10 #include "fpdfsdk/pdfwindow/PWL_ListCtrl.h"
11 #include "fpdfsdk/pdfwindow/PWL_ScrollBar.h"
12 #include "fpdfsdk/pdfwindow/PWL_Utils.h"
13 #include "fpdfsdk/pdfwindow/PWL_Wnd.h"
14 #include "public/fpdf_fwlevent.h"
15
16 #define PWL_IconList_ITEM_ICON_LEFTMARGIN 10.0f
17 #define PWL_IconList_ITEM_WIDTH 20.0f
18 #define PWL_IconList_ITEM_HEIGHT 20.0f
19 #define PWL_IconList_ITEM_SPACE 4.0f
20
21 CPWL_IconList_Item::CPWL_IconList_Item()
22 : m_nIconIndex(-1),
23 m_pData(nullptr),
24 m_bSelected(FALSE),
25 m_pText(nullptr) {}
26
27 CPWL_IconList_Item::~CPWL_IconList_Item() {}
28
29 CFX_ByteString CPWL_IconList_Item::GetClassName() const {
30 return "CPWL_IconList_Item";
31 }
32
33 FX_FLOAT CPWL_IconList_Item::GetItemHeight(FX_FLOAT fLimitWidth) {
34 return PWL_IconList_ITEM_HEIGHT;
35 }
36
37 void CPWL_IconList_Item::DrawThisAppearance(CFX_RenderDevice* pDevice,
38 CFX_Matrix* pUser2Device) {
39 CFX_FloatRect rcClient = GetClientRect();
40
41 if (m_bSelected) {
42 if (IsEnabled()) {
43 CPWL_Utils::DrawFillRect(
44 pDevice, pUser2Device, rcClient,
45 CPWL_Utils::PWLColorToFXColor(PWL_DEFAULT_SELBACKCOLOR,
46 GetTransparency()));
47 } else {
48 CPWL_Utils::DrawFillRect(
49 pDevice, pUser2Device, rcClient,
50 CPWL_Utils::PWLColorToFXColor(PWL_DEFAULT_LIGHTGRAYCOLOR,
51 GetTransparency()));
52 }
53 }
54
55 CFX_FloatRect rcIcon = rcClient;
56 rcIcon.left += PWL_IconList_ITEM_ICON_LEFTMARGIN;
57 rcIcon.right = rcIcon.left + PWL_IconList_ITEM_WIDTH;
58
59 CPWL_Utils::DrawIconAppStream(pDevice, pUser2Device, m_nIconIndex, rcIcon,
60 m_crIcon, m_pText->GetTextColor(),
61 GetTransparency());
62 }
63
64 void CPWL_IconList_Item::SetSelect(FX_BOOL bSelected) {
65 m_bSelected = bSelected;
66
67 if (bSelected)
68 m_pText->SetTextColor(PWL_DEFAULT_WHITECOLOR);
69 else
70 m_pText->SetTextColor(PWL_DEFAULT_BLACKCOLOR);
71 }
72
73 FX_BOOL CPWL_IconList_Item::IsSelected() const {
74 return m_bSelected;
75 }
76
77 void CPWL_IconList_Item::CreateChildWnd(const PWL_CREATEPARAM& cp) {
78 m_pText = new CPWL_Label;
79
80 PWL_CREATEPARAM lcp = cp;
81 lcp.pParentWnd = this;
82 lcp.dwFlags = PWS_CHILD | PWS_VISIBLE | PES_LEFT | PES_CENTER;
83 lcp.sTextColor = PWL_DEFAULT_BLACKCOLOR;
84 lcp.fFontSize = 12;
85 m_pText->Create(lcp);
86 }
87
88 void CPWL_IconList_Item::SetData(void* pData) {
89 m_pData = pData;
90 }
91
92 void CPWL_IconList_Item::SetIcon(int32_t nIconIndex) {
93 m_nIconIndex = nIconIndex;
94 }
95
96 void CPWL_IconList_Item::SetText(const CFX_WideString& str) {
97 m_pText->SetText(str.c_str());
98 }
99
100 CFX_WideString CPWL_IconList_Item::GetText() const {
101 return m_pText->GetText();
102 }
103
104 void CPWL_IconList_Item::RePosChildWnd() {
105 CFX_FloatRect rcClient = GetClientRect();
106
107 rcClient.left +=
108 (PWL_IconList_ITEM_ICON_LEFTMARGIN + PWL_IconList_ITEM_WIDTH +
109 PWL_IconList_ITEM_ICON_LEFTMARGIN);
110
111 m_pText->Move(rcClient, TRUE, FALSE);
112 }
113
114 void CPWL_IconList_Item::SetIconFillColor(const CPWL_Color& color) {
115 m_crIcon = color;
116 }
117
118 void CPWL_IconList_Item::OnEnabled() {
119 if (m_bSelected)
120 m_pText->SetTextColor(PWL_DEFAULT_WHITECOLOR);
121 else
122 m_pText->SetTextColor(PWL_DEFAULT_BLACKCOLOR);
123
124 InvalidateRect();
125 }
126
127 void CPWL_IconList_Item::OnDisabled() {
128 m_pText->SetTextColor(PWL_DEFAULT_HEAVYGRAYCOLOR);
129
130 InvalidateRect();
131 }
132
133 CPWL_IconList_Content::CPWL_IconList_Content(int32_t nListCount)
134 : m_nSelectIndex(-1),
135 m_bMouseDown(FALSE),
136 m_nListCount(nListCount) {}
137
138 CPWL_IconList_Content::~CPWL_IconList_Content() {}
139
140 void CPWL_IconList_Content::CreateChildWnd(const PWL_CREATEPARAM& cp) {
141 for (int32_t i = 0; i < m_nListCount; i++) {
142 CPWL_IconList_Item* pNewItem = new CPWL_IconList_Item();
143
144 PWL_CREATEPARAM icp = cp;
145 icp.pParentWnd = this;
146 icp.dwFlags = PWS_CHILD | PWS_VISIBLE | PWS_NOREFRESHCLIP;
147 pNewItem->Create(icp);
148 }
149
150 SetItemSpace(PWL_IconList_ITEM_SPACE);
151 ResetContent(0);
152
153 if (CPWL_Wnd* pParent = GetParentWindow()) {
154 CFX_FloatRect rcScroll = GetScrollArea();
155 GetScrollPos();
156
157 PWL_SCROLL_INFO sInfo;
158 sInfo.fContentMin = rcScroll.bottom;
159 sInfo.fContentMax = rcScroll.top;
160 sInfo.fPlateWidth = GetClientRect().Height();
161 sInfo.fSmallStep = 13.0f;
162 sInfo.fBigStep = sInfo.fPlateWidth;
163
164 pParent->OnNotify(this, PNM_SETSCROLLINFO, SBT_VSCROLL, (intptr_t)&sInfo);
165 }
166 }
167
168 FX_BOOL CPWL_IconList_Content::OnLButtonDown(const CFX_FloatPoint& point,
169 uint32_t nFlag) {
170 SetFocus();
171
172 SetCapture();
173 m_bMouseDown = TRUE;
174
175 int32_t nItemIndex = FindItemIndex(point);
176 SetSelect(nItemIndex);
177 ScrollToItem(nItemIndex);
178
179 return TRUE;
180 }
181
182 FX_BOOL CPWL_IconList_Content::OnLButtonUp(const CFX_FloatPoint& point,
183 uint32_t nFlag) {
184 m_bMouseDown = FALSE;
185 ReleaseCapture();
186
187 return TRUE;
188 }
189
190 FX_BOOL CPWL_IconList_Content::OnMouseMove(const CFX_FloatPoint& point,
191 uint32_t nFlag) {
192 if (m_bMouseDown) {
193 int32_t nItemIndex = FindItemIndex(point);
194 SetSelect(nItemIndex);
195 ScrollToItem(nItemIndex);
196 }
197
198 return TRUE;
199 }
200
201 FX_BOOL CPWL_IconList_Content::OnKeyDown(uint16_t nChar, uint32_t nFlag) {
202 switch (nChar) {
203 case FWL_VKEY_Up:
204 if (m_nSelectIndex > 0) {
205 int32_t nItemIndex = m_nSelectIndex - 1;
206 SetSelect(nItemIndex);
207 ScrollToItem(nItemIndex);
208 }
209 return TRUE;
210 case FWL_VKEY_Down:
211 if (m_nSelectIndex < m_nListCount - 1) {
212 int32_t nItemIndex = m_nSelectIndex + 1;
213 SetSelect(nItemIndex);
214 ScrollToItem(nItemIndex);
215 }
216 return TRUE;
217 }
218
219 return FALSE;
220 }
221
222 int32_t CPWL_IconList_Content::FindItemIndex(const CFX_FloatPoint& point) {
223 int32_t nIndex = 0;
224 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
225 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
226 CFX_FloatRect rcWnd = pChild->ChildToParent(pChild->GetWindowRect());
227
228 if (point.y < rcWnd.top) {
229 nIndex = i;
230 }
231 }
232 }
233
234 return nIndex;
235 }
236
237 void CPWL_IconList_Content::ScrollToItem(int32_t nItemIndex) {
238 CFX_FloatRect rcClient = GetClientRect();
239
240 if (CPWL_IconList_Item* pItem = GetListItem(nItemIndex)) {
241 CFX_FloatRect rcOrigin = pItem->GetWindowRect();
242 CFX_FloatRect rcWnd = pItem->ChildToParent(rcOrigin);
243
244 if (!(rcWnd.bottom > rcClient.bottom && rcWnd.top < rcClient.top)) {
245 CFX_FloatPoint ptScroll = GetScrollPos();
246
247 if (rcWnd.top > rcClient.top) {
248 ptScroll.y = rcOrigin.top;
249 } else if (rcWnd.bottom < rcClient.bottom) {
250 ptScroll.y = rcOrigin.bottom + rcClient.Height();
251 }
252
253 SetScrollPos(ptScroll);
254 ResetFace();
255 InvalidateRect();
256 if (CPWL_Wnd* pParent = GetParentWindow()) {
257 pParent->OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL,
258 (intptr_t)&ptScroll.y);
259 }
260 }
261 }
262 }
263
264 void CPWL_IconList_Content::SetSelect(int32_t nIndex) {
265 if (m_nSelectIndex == nIndex)
266 return;
267
268 SelectItem(m_nSelectIndex, FALSE);
269 SelectItem(nIndex, TRUE);
270 m_nSelectIndex = nIndex;
271 }
272
273 int32_t CPWL_IconList_Content::GetSelect() const {
274 return m_nSelectIndex;
275 }
276
277 void CPWL_IconList_Content::SelectItem(int32_t nItemIndex, FX_BOOL bSelect) {
278 if (CPWL_IconList_Item* pItem = GetListItem(nItemIndex)) {
279 pItem->SetSelect(bSelect);
280 pItem->InvalidateRect();
281 }
282 }
283
284 CPWL_IconList_Item* CPWL_IconList_Content::GetListItem(
285 int32_t nItemIndex) const {
286 if (nItemIndex >= 0 && nItemIndex < m_aChildren.GetSize()) {
287 if (CPWL_Wnd* pChild = m_aChildren.GetAt(nItemIndex)) {
288 if (pChild->GetClassName() == "CPWL_IconList_Item") {
289 return (CPWL_IconList_Item*)pChild;
290 }
291 }
292 }
293
294 return nullptr;
295 }
296
297 void CPWL_IconList_Content::SetListData(int32_t nItemIndex, void* pData) {
298 if (CPWL_IconList_Item* pItem = GetListItem(nItemIndex))
299 pItem->SetData(pData);
300 }
301
302 void CPWL_IconList_Content::SetListIcon(int32_t nItemIndex,
303 int32_t nIconIndex) {
304 if (CPWL_IconList_Item* pItem = GetListItem(nItemIndex))
305 pItem->SetIcon(nIconIndex);
306 }
307
308 void CPWL_IconList_Content::SetListString(int32_t nItemIndex,
309 const CFX_WideString& str) {
310 if (CPWL_IconList_Item* pItem = GetListItem(nItemIndex))
311 pItem->SetText(str);
312 }
313
314 CFX_WideString CPWL_IconList_Content::GetListString(int32_t nItemIndex) const {
315 if (CPWL_IconList_Item* pItem = GetListItem(nItemIndex))
316 return pItem->GetText();
317
318 return L"";
319 }
320
321 void CPWL_IconList_Content::SetIconFillColor(const CPWL_Color& color) {
322 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
323 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
324 if (pChild->GetClassName() == "CPWL_IconList_Item") {
325 CPWL_IconList_Item* pItem = (CPWL_IconList_Item*)pChild;
326 pItem->SetIconFillColor(color);
327 pItem->InvalidateRect();
328 }
329 }
330 }
331 }
332
333 CPWL_IconList::CPWL_IconList(int32_t nListCount)
334 : m_pListContent(nullptr), m_nListCount(nListCount) {}
335
336 CPWL_IconList::~CPWL_IconList() {}
337
338 void CPWL_IconList::RePosChildWnd() {
339 CPWL_Wnd::RePosChildWnd();
340
341 if (m_pListContent)
342 m_pListContent->Move(GetClientRect(), TRUE, FALSE);
343 }
344
345 void CPWL_IconList::CreateChildWnd(const PWL_CREATEPARAM& cp) {
346 m_pListContent = new CPWL_IconList_Content(m_nListCount);
347
348 PWL_CREATEPARAM ccp = cp;
349 ccp.pParentWnd = this;
350 ccp.dwFlags = PWS_CHILD | PWS_VISIBLE;
351 m_pListContent->Create(ccp);
352 }
353
354 void CPWL_IconList::OnCreated() {
355 if (CPWL_ScrollBar* pScrollBar = GetVScrollBar()) {
356 pScrollBar->RemoveFlag(PWS_AUTOTRANSPARENT);
357 pScrollBar->SetTransparency(255);
358 pScrollBar->SetNotifyForever(TRUE);
359 }
360 }
361
362 void CPWL_IconList::OnNotify(CPWL_Wnd* pWnd,
363 uint32_t msg,
364 intptr_t wParam,
365 intptr_t lParam) {
366 CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam);
367
368 if (wParam == SBT_VSCROLL) {
369 switch (msg) {
370 case PNM_SETSCROLLINFO:
371 if (PWL_SCROLL_INFO* pInfo = (PWL_SCROLL_INFO*)lParam) {
372 if (CPWL_ScrollBar* pScrollBar = GetVScrollBar()) {
373 if (pInfo->fContentMax - pInfo->fContentMin > pInfo->fPlateWidth) {
374 if (!pScrollBar->IsVisible()) {
375 pScrollBar->SetVisible(TRUE);
376 RePosChildWnd();
377 } else {
378 }
379 } else {
380 if (pScrollBar->IsVisible()) {
381 pScrollBar->SetVisible(FALSE);
382 RePosChildWnd();
383 }
384
385 if (m_pListContent)
386 m_pListContent->SetScrollPos(CFX_FloatPoint(0.0f, 0.0f));
387 }
388
389 pScrollBar->OnNotify(pWnd, PNM_SETSCROLLINFO, wParam, lParam);
390 }
391 }
392 return;
393 case PNM_SCROLLWINDOW:
394 if (m_pListContent) {
395 m_pListContent->SetScrollPos(
396 CFX_FloatPoint(0.0f, *(FX_FLOAT*)lParam));
397 m_pListContent->ResetFace();
398 m_pListContent->InvalidateRect(nullptr);
399 }
400 return;
401 case PNM_SETSCROLLPOS:
402 if (CPWL_ScrollBar* pScrollBar = GetVScrollBar())
403 pScrollBar->OnNotify(pWnd, PNM_SETSCROLLPOS, wParam, lParam);
404 return;
405 }
406 }
407 }
408
409 void CPWL_IconList::SetSelect(int32_t nIndex) {
410 m_pListContent->SetSelect(nIndex);
411 }
412
413 void CPWL_IconList::SetTopItem(int32_t nIndex) {
414 m_pListContent->ScrollToItem(nIndex);
415 }
416
417 int32_t CPWL_IconList::GetSelect() const {
418 return m_pListContent->GetSelect();
419 }
420
421 void CPWL_IconList::SetListData(int32_t nItemIndex, void* pData) {
422 m_pListContent->SetListData(nItemIndex, pData);
423 }
424
425 void CPWL_IconList::SetListIcon(int32_t nItemIndex, int32_t nIconIndex) {
426 m_pListContent->SetListIcon(nItemIndex, nIconIndex);
427 }
428
429 void CPWL_IconList::SetListString(int32_t nItemIndex,
430 const CFX_WideString& str) {
431 m_pListContent->SetListString(nItemIndex, str);
432 }
433
434 CFX_WideString CPWL_IconList::GetListString(int32_t nItemIndex) const {
435 return m_pListContent->GetListString(nItemIndex);
436 }
437
438 void CPWL_IconList::SetIconFillColor(const CPWL_Color& color) {
439 m_pListContent->SetIconFillColor(color);
440 }
441
442 FX_BOOL CPWL_IconList::OnMouseWheel(short zDelta,
443 const CFX_FloatPoint& point,
444 uint32_t nFlag) {
445 CFX_FloatPoint ptScroll = m_pListContent->GetScrollPos();
446 CFX_FloatRect rcScroll = m_pListContent->GetScrollArea();
447 CFX_FloatRect rcContents = m_pListContent->GetClientRect();
448
449 if (rcScroll.top - rcScroll.bottom > rcContents.Height()) {
450 CFX_FloatPoint ptNew = ptScroll;
451
452 if (zDelta > 0)
453 ptNew.y += 30;
454 else
455 ptNew.y -= 30;
456
457 if (ptNew.y > rcScroll.top)
458 ptNew.y = rcScroll.top;
459 if (ptNew.y < rcScroll.bottom + rcContents.Height())
460 ptNew.y = rcScroll.bottom + rcContents.Height();
461 if (ptNew.y < rcScroll.bottom)
462 ptNew.y = rcScroll.bottom;
463
464 if (ptNew.y != ptScroll.y) {
465 m_pListContent->SetScrollPos(ptNew);
466 m_pListContent->ResetFace();
467 m_pListContent->InvalidateRect(nullptr);
468
469 if (CPWL_ScrollBar* pScrollBar = GetVScrollBar())
470 pScrollBar->OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL,
471 (intptr_t)&ptNew.y);
472
473 return TRUE;
474 }
475 }
476
477 return FALSE;
478 }
OLDNEW
« no previous file with comments | « fpdfsdk/pdfwindow/PWL_IconList.h ('k') | fpdfsdk/pdfwindow/PWL_Label.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698