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

Side by Side Diff: fpdfsdk/src/pdfwindow/PWL_IconList.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/pdfwindow/PDFWindow.h" 7 #include "../../include/pdfwindow/PDFWindow.h"
8 #include "../../include/pdfwindow/PWL_Wnd.h" 8 #include "../../include/pdfwindow/PWL_Wnd.h"
9 #include "../../include/pdfwindow/PWL_ListCtrl.h" 9 #include "../../include/pdfwindow/PWL_ListCtrl.h"
10 #include "../../include/pdfwindow/PWL_IconList.h" 10 #include "../../include/pdfwindow/PWL_IconList.h"
11 #include "../../include/pdfwindow/PWL_Utils.h" 11 #include "../../include/pdfwindow/PWL_Utils.h"
12 #include "../../include/pdfwindow/PWL_ScrollBar.h" 12 #include "../../include/pdfwindow/PWL_ScrollBar.h"
13 #include "../../include/pdfwindow/PWL_Label.h" 13 #include "../../include/pdfwindow/PWL_Label.h"
14 14
15 #define PWL_IconList_ITEM_ICON_LEFTMARGIN» » 10.0f 15 #define PWL_IconList_ITEM_ICON_LEFTMARGIN 10.0f
16 #define PWL_IconList_ITEM_WIDTH»» » » » 20.0f 16 #define PWL_IconList_ITEM_WIDTH 20.0f
17 #define PWL_IconList_ITEM_HEIGHT» » » » 20.0f 17 #define PWL_IconList_ITEM_HEIGHT 20.0f
18 #define PWL_IconList_ITEM_SPACE»» » » » 4.0f 18 #define PWL_IconList_ITEM_SPACE 4.0f
19 19
20 /* ------------------ CPWL_IconList_Item ------------------- */ 20 /* ------------------ CPWL_IconList_Item ------------------- */
21 21
22 CPWL_IconList_Item::CPWL_IconList_Item() : 22 CPWL_IconList_Item::CPWL_IconList_Item()
23 » m_nIconIndex(-1), 23 : m_nIconIndex(-1), m_pData(NULL), m_bSelected(FALSE), m_pText(NULL) {}
24 » m_pData(NULL), 24
25 » m_bSelected(FALSE), 25 CPWL_IconList_Item::~CPWL_IconList_Item() {}
26 » m_pText(NULL) 26
27 { 27 CFX_ByteString CPWL_IconList_Item::GetClassName() const {
28 } 28 return "CPWL_IconList_Item";
29 29 }
30 CPWL_IconList_Item::~CPWL_IconList_Item() 30
31 { 31 FX_FLOAT CPWL_IconList_Item::GetItemHeight(FX_FLOAT fLimitWidth) {
32 } 32 return PWL_IconList_ITEM_HEIGHT;
33 33 }
34 CFX_ByteString CPWL_IconList_Item::GetClassName() const 34
35 { 35 void CPWL_IconList_Item::DrawThisAppearance(CFX_RenderDevice* pDevice,
36 » return "CPWL_IconList_Item"; 36 CPDF_Matrix* pUser2Device) {
37 } 37 CPDF_Rect rcClient = GetClientRect();
38 38
39 FX_FLOAT CPWL_IconList_Item::GetItemHeight(FX_FLOAT fLimitWidth) 39 if (m_bSelected) {
40 { 40 if (IsEnabled()) {
41 » return PWL_IconList_ITEM_HEIGHT; 41 CPWL_Utils::DrawFillRect(
42 } 42 pDevice, pUser2Device, rcClient,
43 43 CPWL_Utils::PWLColorToFXColor(PWL_DEFAULT_SELBACKCOLOR,
44 void CPWL_IconList_Item::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matr ix* pUser2Device) 44 GetTransparency()));
45 { 45 } else {
46 » CPDF_Rect rcClient = GetClientRect(); 46 CPWL_Utils::DrawFillRect(
47 47 pDevice, pUser2Device, rcClient,
48 » if (m_bSelected) 48 CPWL_Utils::PWLColorToFXColor(PWL_DEFAULT_LIGHTGRAYCOLOR,
49 » { 49 GetTransparency()));
50 » » if (IsEnabled()) 50 }
51 » » { 51 }
52 » » » CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcClient , 52
53 » » » » CPWL_Utils::PWLColorToFXColor(PWL_DEFAULT_SELBAC KCOLOR, GetTransparency())); 53 CPDF_Rect rcIcon = rcClient;
54 » » } 54 rcIcon.left += PWL_IconList_ITEM_ICON_LEFTMARGIN;
55 » » else 55 rcIcon.right = rcIcon.left + PWL_IconList_ITEM_WIDTH;
56 » » { 56
57 » » » CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcClient , 57 CPWL_Utils::DrawIconAppStream(pDevice, pUser2Device, m_nIconIndex, rcIcon,
58 » » » » CPWL_Utils::PWLColorToFXColor(PWL_DEFAULT_LIGHTG RAYCOLOR, GetTransparency())); 58 m_crIcon, m_pText->GetTextColor(),
59 » » } 59 GetTransparency());
60 » } 60 }
61 61
62 » CPDF_Rect rcIcon = rcClient; 62 void CPWL_IconList_Item::SetSelect(FX_BOOL bSelected) {
63 » rcIcon.left += PWL_IconList_ITEM_ICON_LEFTMARGIN; 63 m_bSelected = bSelected;
64 » rcIcon.right = rcIcon.left + PWL_IconList_ITEM_WIDTH; 64
65 65 if (bSelected)
66 » CPWL_Utils::DrawIconAppStream(pDevice, pUser2Device, m_nIconIndex, rcIco n, 66 m_pText->SetTextColor(PWL_DEFAULT_WHITECOLOR);
67 » » m_crIcon, m_pText->GetTextColor(), GetTransparency()); 67 else
68 } 68 m_pText->SetTextColor(PWL_DEFAULT_BLACKCOLOR);
69 69 }
70 void CPWL_IconList_Item::SetSelect(FX_BOOL bSelected) 70
71 { 71 FX_BOOL CPWL_IconList_Item::IsSelected() const {
72 » m_bSelected = bSelected; 72 return m_bSelected;
73 73 }
74 » if (bSelected) 74
75 » » m_pText->SetTextColor(PWL_DEFAULT_WHITECOLOR); 75 void CPWL_IconList_Item::CreateChildWnd(const PWL_CREATEPARAM& cp) {
76 » else 76 m_pText = new CPWL_Label;
77 » » m_pText->SetTextColor(PWL_DEFAULT_BLACKCOLOR); 77
78 78 PWL_CREATEPARAM lcp = cp;
79 } 79 lcp.pParentWnd = this;
80 80 lcp.dwFlags = PWS_CHILD | PWS_VISIBLE | PES_LEFT | PES_CENTER;
81 FX_BOOL»CPWL_IconList_Item::IsSelected() const 81 lcp.sTextColor = PWL_DEFAULT_BLACKCOLOR;
82 { 82 lcp.fFontSize = 12;
83 » return m_bSelected; 83 m_pText->Create(lcp);
84 } 84 }
85 85
86 void CPWL_IconList_Item::CreateChildWnd(const PWL_CREATEPARAM & cp) 86 void CPWL_IconList_Item::SetData(void* pData) {
87 { 87 m_pData = pData;
88 » m_pText = new CPWL_Label; 88 }
89 89
90 » PWL_CREATEPARAM lcp = cp; 90 void CPWL_IconList_Item::SetIcon(int32_t nIconIndex) {
91 » lcp.pParentWnd = this; 91 m_nIconIndex = nIconIndex;
92 » lcp.dwFlags = PWS_CHILD | PWS_VISIBLE | PES_LEFT | PES_CENTER; 92 }
93 » lcp.sTextColor = PWL_DEFAULT_BLACKCOLOR; 93
94 » lcp.fFontSize = 12; 94 void CPWL_IconList_Item::SetText(const CFX_WideString& str) {
95 » m_pText->Create(lcp); 95 m_pText->SetText(str.c_str());
96 } 96 }
97 97
98 void CPWL_IconList_Item::SetData(void* pData) 98 CFX_WideString CPWL_IconList_Item::GetText() const {
99 { 99 return m_pText->GetText();
100 » m_pData = pData; 100 }
101 } 101
102 102 void CPWL_IconList_Item::RePosChildWnd() {
103 void CPWL_IconList_Item::SetIcon(int32_t nIconIndex) 103 CPDF_Rect rcClient = GetClientRect();
104 { 104
105 » m_nIconIndex = nIconIndex; 105 rcClient.left +=
106 } 106 (PWL_IconList_ITEM_ICON_LEFTMARGIN + PWL_IconList_ITEM_WIDTH +
107 107 PWL_IconList_ITEM_ICON_LEFTMARGIN);
108 void CPWL_IconList_Item::SetText(const CFX_WideString& str) 108
109 { 109 m_pText->Move(rcClient, TRUE, FALSE);
110 » m_pText->SetText(str.c_str()); 110 }
111 } 111
112 112 void CPWL_IconList_Item::SetIconFillColor(const CPWL_Color& color) {
113 CFX_WideString CPWL_IconList_Item::GetText() const 113 m_crIcon = color;
114 { 114 }
115 » return m_pText->GetText(); 115
116 } 116 void CPWL_IconList_Item::OnEnabled() {
117 117 if (m_bSelected)
118 void CPWL_IconList_Item::RePosChildWnd() 118 m_pText->SetTextColor(PWL_DEFAULT_WHITECOLOR);
119 { 119 else
120 » CPDF_Rect rcClient = GetClientRect(); 120 m_pText->SetTextColor(PWL_DEFAULT_BLACKCOLOR);
121 121
122 » rcClient.left += (PWL_IconList_ITEM_ICON_LEFTMARGIN + PWL_IconList_ITEM_ WIDTH + PWL_IconList_ITEM_ICON_LEFTMARGIN); 122 InvalidateRect();
123 123 }
124 » m_pText->Move(rcClient, TRUE, FALSE); 124
125 } 125 void CPWL_IconList_Item::OnDisabled() {
126 126 m_pText->SetTextColor(PWL_DEFAULT_HEAVYGRAYCOLOR);
127 void CPWL_IconList_Item::SetIconFillColor(const CPWL_Color& color) 127
128 { 128 InvalidateRect();
129 » m_crIcon = color;
130 }
131
132 void CPWL_IconList_Item::OnEnabled()
133 {
134 » if (m_bSelected)
135 » » m_pText->SetTextColor(PWL_DEFAULT_WHITECOLOR);
136 » else
137 » » m_pText->SetTextColor(PWL_DEFAULT_BLACKCOLOR);
138
139 » InvalidateRect();
140 }
141
142 void CPWL_IconList_Item::OnDisabled()
143 {
144 » m_pText->SetTextColor(PWL_DEFAULT_HEAVYGRAYCOLOR);
145
146 » InvalidateRect();
147 } 129 }
148 130
149 /* ----------------- CPWL_IconList_Content ----------------- */ 131 /* ----------------- CPWL_IconList_Content ----------------- */
150 132
151 CPWL_IconList_Content::CPWL_IconList_Content(int32_t nListCount) : 133 CPWL_IconList_Content::CPWL_IconList_Content(int32_t nListCount)
152 m_nSelectIndex(-1), 134 : m_nSelectIndex(-1),
153 m_pNotify(NULL), 135 m_pNotify(NULL),
154 m_bEnableNotify(TRUE), 136 m_bEnableNotify(TRUE),
155 m_bMouseDown(FALSE), 137 m_bMouseDown(FALSE),
156 m_nListCount(nListCount) 138 m_nListCount(nListCount) {}
157 { 139
158 } 140 CPWL_IconList_Content::~CPWL_IconList_Content() {}
159 141
160 CPWL_IconList_Content::~CPWL_IconList_Content() 142 void CPWL_IconList_Content::CreateChildWnd(const PWL_CREATEPARAM& cp) {
161 { 143 for (int32_t i = 0; i < m_nListCount; i++) {
162 } 144 CPWL_IconList_Item* pNewItem = new CPWL_IconList_Item();
163 145
164 void CPWL_IconList_Content::CreateChildWnd(const PWL_CREATEPARAM & cp) 146 PWL_CREATEPARAM icp = cp;
165 { 147 icp.pParentWnd = this;
166 for (int32_t i=0; i<m_nListCount; i++) 148 icp.dwFlags = PWS_CHILD | PWS_VISIBLE | PWS_NOREFRESHCLIP;
167 { 149 pNewItem->Create(icp);
168 CPWL_IconList_Item* pNewItem = new CPWL_IconList_Item(); 150 }
169 151
170 PWL_CREATEPARAM icp = cp; 152 SetItemSpace(PWL_IconList_ITEM_SPACE);
171 icp.pParentWnd = this; 153 ResetContent(0);
172 icp.dwFlags = PWS_CHILD | PWS_VISIBLE | PWS_NOREFRESHCLIP; 154
173 pNewItem->Create(icp); 155 if (CPWL_Wnd* pParent = GetParentWindow()) {
174 } 156 CPDF_Rect rcScroll = GetScrollArea();
175 157 GetScrollPos();
176 SetItemSpace(PWL_IconList_ITEM_SPACE); 158
177 ResetContent(0); 159 PWL_SCROLL_INFO sInfo;
178 160 sInfo.fContentMin = rcScroll.bottom;
179 if (CPWL_Wnd * pParent = GetParentWindow()) 161 sInfo.fContentMax = rcScroll.top;
180 { 162 sInfo.fPlateWidth = GetClientRect().Height();
181 CPDF_Rect rcScroll = GetScrollArea(); 163 sInfo.fSmallStep = 13.0f;
182 GetScrollPos(); 164 sInfo.fBigStep = sInfo.fPlateWidth;
183 165
184 PWL_SCROLL_INFO sInfo; 166 pParent->OnNotify(this, PNM_SETSCROLLINFO, SBT_VSCROLL, (intptr_t)&sInfo);
185 sInfo.fContentMin = rcScroll.bottom; 167 }
186 sInfo.fContentMax = rcScroll.top; 168 }
187 sInfo.fPlateWidth = GetClientRect().Height(); 169
188 sInfo.fSmallStep = 13.0f; 170 FX_BOOL CPWL_IconList_Content::OnLButtonDown(const CPDF_Point& point,
189 sInfo.fBigStep = sInfo.fPlateWidth; 171 FX_DWORD nFlag) {
190 172 SetFocus();
191 pParent->OnNotify(this, PNM_SETSCROLLINFO, SBT_VSCROLL, (intptr_ t)&sInfo); 173
192 } 174 SetCapture();
193 } 175 m_bMouseDown = TRUE;
194 176
195 FX_BOOL CPWL_IconList_Content::OnLButtonDown(const CPDF_Point & point, FX_DWORD nFlag) 177 int32_t nItemIndex = FindItemIndex(point);
196 { 178 SetSelect(nItemIndex);
197 SetFocus(); 179 ScrollToItem(nItemIndex);
198 180
199 SetCapture(); 181 return TRUE;
200 m_bMouseDown = TRUE; 182 }
201 183
202 int32_t nItemIndex = FindItemIndex(point); 184 FX_BOOL CPWL_IconList_Content::OnLButtonUp(const CPDF_Point& point,
203 SetSelect(nItemIndex); 185 FX_DWORD nFlag) {
204 ScrollToItem(nItemIndex); 186 m_bMouseDown = FALSE;
205 187 ReleaseCapture();
206 return TRUE; 188
207 } 189 return TRUE;
208 190 }
209 FX_BOOL CPWL_IconList_Content::OnLButtonUp(const CPDF_Point & point, FX_DWORD nF lag) 191
210 { 192 FX_BOOL CPWL_IconList_Content::OnMouseMove(const CPDF_Point& point,
211 m_bMouseDown = FALSE; 193 FX_DWORD nFlag) {
212 ReleaseCapture(); 194 if (m_bMouseDown) {
213 195 int32_t nItemIndex = FindItemIndex(point);
214 return TRUE; 196 SetSelect(nItemIndex);
215 } 197 ScrollToItem(nItemIndex);
216 198 }
217 FX_BOOL CPWL_IconList_Content::OnMouseMove(const CPDF_Point & point, FX_DWORD nF lag) 199
218 { 200 return TRUE;
219 if (m_bMouseDown) 201 }
220 { 202
221 int32_t nItemIndex = FindItemIndex(point); 203 FX_BOOL CPWL_IconList_Content::OnKeyDown(FX_WORD nChar, FX_DWORD nFlag) {
222 SetSelect(nItemIndex); 204 switch (nChar) {
223 ScrollToItem(nItemIndex); 205 case FWL_VKEY_Up:
224 } 206 if (m_nSelectIndex > 0) {
225 207 int32_t nItemIndex = m_nSelectIndex - 1;
226 return TRUE; 208 SetSelect(nItemIndex);
227 } 209 ScrollToItem(nItemIndex);
228 210 }
229 FX_BOOL CPWL_IconList_Content::OnKeyDown(FX_WORD nChar, FX_DWORD nFlag) 211 return TRUE;
230 { 212 case FWL_VKEY_Down:
231 switch (nChar) 213 if (m_nSelectIndex < m_nListCount - 1) {
232 { 214 int32_t nItemIndex = m_nSelectIndex + 1;
233 case FWL_VKEY_Up: 215 SetSelect(nItemIndex);
234 if (m_nSelectIndex > 0) 216 ScrollToItem(nItemIndex);
235 { 217 }
236 int32_t nItemIndex = m_nSelectIndex - 1; 218 return TRUE;
237 SetSelect(nItemIndex); 219 }
238 ScrollToItem(nItemIndex); 220
239 } 221 return FALSE;
240 return TRUE; 222 }
241 case FWL_VKEY_Down: 223
242 if (m_nSelectIndex < m_nListCount-1) 224 int32_t CPWL_IconList_Content::FindItemIndex(const CPDF_Point& point) {
243 { 225 int32_t nIndex = 0;
244 int32_t nItemIndex = m_nSelectIndex + 1; 226 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
245 SetSelect(nItemIndex); 227 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
246 ScrollToItem(nItemIndex); 228 CPDF_Rect rcWnd = pChild->ChildToParent(pChild->GetWindowRect());
247 } 229
248 return TRUE; 230 if (point.y < rcWnd.top) {
249 } 231 nIndex = i;
250 232 }
251 return FALSE; 233 }
252 } 234 }
253 235
254 int32_t CPWL_IconList_Content::FindItemIndex(const CPDF_Point& point) 236 return nIndex;
255 { 237 }
256 int32_t nIndex = 0; 238
257 for (int32_t i=0,sz=m_aChildren.GetSize(); i<sz; i++) 239 void CPWL_IconList_Content::ScrollToItem(int32_t nItemIndex) {
258 { 240 CPDF_Rect rcClient = GetClientRect();
259 if (CPWL_Wnd * pChild = m_aChildren.GetAt(i)) 241
260 { 242 if (CPWL_IconList_Item* pItem = GetListItem(nItemIndex)) {
261 CPDF_Rect rcWnd = pChild->ChildToParent(pChild->GetWindo wRect()); 243 CPDF_Rect rcOrigin = pItem->GetWindowRect();
262 244 CPDF_Rect rcWnd = pItem->ChildToParent(rcOrigin);
263 if (point.y < rcWnd.top) 245
264 { 246 if (!(rcWnd.bottom > rcClient.bottom && rcWnd.top < rcClient.top)) {
265 nIndex = i; 247 CPDF_Point ptScroll = GetScrollPos();
266 } 248
267 } 249 if (rcWnd.top > rcClient.top) {
268 } 250 ptScroll.y = rcOrigin.top;
269 251 } else if (rcWnd.bottom < rcClient.bottom) {
270 return nIndex; 252 ptScroll.y = rcOrigin.bottom + rcClient.Height();
271 } 253 }
272 254
273 void CPWL_IconList_Content::ScrollToItem(int32_t nItemIndex) 255 SetScrollPos(ptScroll);
274 { 256 ResetFace();
275 CPDF_Rect rcClient = GetClientRect(); 257 InvalidateRect();
276 258 if (CPWL_Wnd* pParent = GetParentWindow()) {
277 if (CPWL_IconList_Item* pItem = GetListItem(nItemIndex)) 259 pParent->OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL,
278 { 260 (intptr_t)&ptScroll.y);
279 CPDF_Rect rcOrigin = pItem->GetWindowRect(); 261 }
280 CPDF_Rect rcWnd = pItem->ChildToParent(rcOrigin); 262 }
281 263 }
282 if (!(rcWnd.bottom > rcClient.bottom && rcWnd.top < rcClient.top )) 264 }
283 { 265
284 CPDF_Point ptScroll = GetScrollPos(); 266 void CPWL_IconList_Content::SetSelect(int32_t nIndex) {
285 267 if (m_nSelectIndex != nIndex) {
286 if (rcWnd.top > rcClient.top) 268 SelectItem(m_nSelectIndex, FALSE);
287 { 269 SelectItem(nIndex, TRUE);
288 ptScroll.y = rcOrigin.top; 270 m_nSelectIndex = nIndex;
289 } 271
290 else if (rcWnd.bottom < rcClient.bottom) 272 if (IPWL_IconList_Notify* pNotify = GetNotify())
291 { 273 pNotify->OnNoteListSelChanged(nIndex);
292 ptScroll.y = rcOrigin.bottom + rcClient.Height() ; 274 }
293 } 275 }
294 276
295 SetScrollPos(ptScroll); 277 int32_t CPWL_IconList_Content::GetSelect() const {
296 ResetFace(); 278 return m_nSelectIndex;
297 InvalidateRect(); 279 }
298 if (CPWL_Wnd* pParent = GetParentWindow()) 280
299 { 281 IPWL_IconList_Notify* CPWL_IconList_Content::GetNotify() const {
300 pParent->OnNotify(this, PNM_SETSCROLLPOS, SBT_VS CROLL, (intptr_t)&ptScroll.y); 282 if (m_bEnableNotify)
301 } 283 return m_pNotify;
302 } 284 return NULL;
303 } 285 }
304 } 286
305 287 void CPWL_IconList_Content::SetNotify(IPWL_IconList_Notify* pNotify) {
306 void CPWL_IconList_Content::SetSelect(int32_t nIndex) 288 m_pNotify = pNotify;
307 { 289 }
308 if (m_nSelectIndex != nIndex) 290
309 { 291 void CPWL_IconList_Content::EnableNotify(FX_BOOL bNotify) {
310 SelectItem(m_nSelectIndex, FALSE); 292 m_bEnableNotify = bNotify;
311 SelectItem(nIndex, TRUE); 293 }
312 m_nSelectIndex = nIndex; 294
313 295 void CPWL_IconList_Content::SelectItem(int32_t nItemIndex, FX_BOOL bSelect) {
314 if (IPWL_IconList_Notify* pNotify = GetNotify()) 296 if (CPWL_IconList_Item* pItem = GetListItem(nItemIndex)) {
315 pNotify->OnNoteListSelChanged(nIndex); 297 pItem->SetSelect(bSelect);
316 } 298 pItem->InvalidateRect();
317 } 299 }
318 300 }
319 int32_t CPWL_IconList_Content::GetSelect() const 301
320 { 302 CPWL_IconList_Item* CPWL_IconList_Content::GetListItem(
321 return m_nSelectIndex; 303 int32_t nItemIndex) const {
322 } 304 if (nItemIndex >= 0 && nItemIndex < m_aChildren.GetSize()) {
323 305 if (CPWL_Wnd* pChild = m_aChildren.GetAt(nItemIndex)) {
324 IPWL_IconList_Notify* CPWL_IconList_Content::GetNotify() const 306 if (pChild->GetClassName() == "CPWL_IconList_Item") {
325 { 307 return (CPWL_IconList_Item*)pChild;
326 if (m_bEnableNotify) 308 }
327 return m_pNotify; 309 }
328 return NULL; 310 }
329 } 311
330 312 return NULL;
331 void CPWL_IconList_Content::SetNotify(IPWL_IconList_Notify* pNotify) 313 }
332 { 314
333 m_pNotify = pNotify; 315 void CPWL_IconList_Content::SetListData(int32_t nItemIndex, void* pData) {
334 } 316 if (CPWL_IconList_Item* pItem = GetListItem(nItemIndex))
335 317 pItem->SetData(pData);
336 void CPWL_IconList_Content::EnableNotify(FX_BOOL bNotify) 318 }
337 { 319
338 m_bEnableNotify = bNotify; 320 void CPWL_IconList_Content::SetListIcon(int32_t nItemIndex,
339 } 321 int32_t nIconIndex) {
340 322 if (CPWL_IconList_Item* pItem = GetListItem(nItemIndex))
341 void CPWL_IconList_Content::SelectItem(int32_t nItemIndex, FX_BOOL bSelect) 323 pItem->SetIcon(nIconIndex);
342 { 324 }
343 if (CPWL_IconList_Item* pItem = GetListItem(nItemIndex)) 325
344 { 326 void CPWL_IconList_Content::SetListString(int32_t nItemIndex,
345 pItem->SetSelect(bSelect); 327 const CFX_WideString& str) {
346 pItem->InvalidateRect(); 328 if (CPWL_IconList_Item* pItem = GetListItem(nItemIndex))
347 } 329 pItem->SetText(str);
348 } 330 }
349 331
350 CPWL_IconList_Item* CPWL_IconList_Content::GetListItem(int32_t nItemIndex) const 332 CFX_WideString CPWL_IconList_Content::GetListString(int32_t nItemIndex) const {
351 { 333 if (CPWL_IconList_Item* pItem = GetListItem(nItemIndex))
352 if (nItemIndex >= 0 && nItemIndex<m_aChildren.GetSize()) 334 return pItem->GetText();
353 { 335
354 if (CPWL_Wnd * pChild = m_aChildren.GetAt(nItemIndex)) 336 return L"";
355 { 337 }
356 if (pChild->GetClassName() == "CPWL_IconList_Item") 338
357 { 339 void CPWL_IconList_Content::SetIconFillColor(const CPWL_Color& color) {
358 return (CPWL_IconList_Item*)pChild; 340 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
359 } 341 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
360 } 342 if (pChild->GetClassName() == "CPWL_IconList_Item") {
361 } 343 CPWL_IconList_Item* pItem = (CPWL_IconList_Item*)pChild;
362 344 pItem->SetIconFillColor(color);
363 return NULL; 345 pItem->InvalidateRect();
364 } 346 }
365 347 }
366 void CPWL_IconList_Content::SetListData(int32_t nItemIndex, void* pData) 348 }
367 {
368 if (CPWL_IconList_Item* pItem = GetListItem(nItemIndex))
369 pItem->SetData(pData);
370 }
371
372 void CPWL_IconList_Content::SetListIcon(int32_t nItemIndex, int32_t nIconIndex)
373 {
374 if (CPWL_IconList_Item* pItem = GetListItem(nItemIndex))
375 pItem->SetIcon(nIconIndex);
376 }
377
378 void CPWL_IconList_Content::SetListString(int32_t nItemIndex, const CFX_WideStri ng& str)
379 {
380 if (CPWL_IconList_Item* pItem = GetListItem(nItemIndex))
381 pItem->SetText(str);
382 }
383
384 CFX_WideString CPWL_IconList_Content::GetListString(int32_t nItemIndex) const
385 {
386 if (CPWL_IconList_Item* pItem = GetListItem(nItemIndex))
387 return pItem->GetText();
388
389 return L"";
390 }
391
392 void CPWL_IconList_Content::SetIconFillColor(const CPWL_Color& color)
393 {
394 for (int32_t i=0,sz=m_aChildren.GetSize(); i<sz; i++)
395 {
396 if (CPWL_Wnd * pChild = m_aChildren.GetAt(i))
397 {
398 if (pChild->GetClassName() == "CPWL_IconList_Item")
399 {
400 CPWL_IconList_Item* pItem = (CPWL_IconList_Item* )pChild;
401 pItem->SetIconFillColor(color);
402 pItem->InvalidateRect();
403 }
404 }
405 }
406
407 } 349 }
408 350
409 /* -------------------- CPWL_IconList --------------------- */ 351 /* -------------------- CPWL_IconList --------------------- */
410 352
411 CPWL_IconList::CPWL_IconList(int32_t nListCount) : 353 CPWL_IconList::CPWL_IconList(int32_t nListCount)
412 » m_pListContent(NULL), 354 : m_pListContent(NULL), m_nListCount(nListCount) {}
413 » m_nListCount(nListCount) 355
414 { 356 CPWL_IconList::~CPWL_IconList() {}
415 } 357
416 358 void CPWL_IconList::RePosChildWnd() {
417 CPWL_IconList::~CPWL_IconList() 359 CPWL_Wnd::RePosChildWnd();
418 { 360
419 } 361 if (m_pListContent)
420 362 m_pListContent->Move(GetClientRect(), TRUE, FALSE);
421 void CPWL_IconList::RePosChildWnd() 363 }
422 { 364
423 » CPWL_Wnd::RePosChildWnd(); 365 void CPWL_IconList::CreateChildWnd(const PWL_CREATEPARAM& cp) {
424 366 m_pListContent = new CPWL_IconList_Content(m_nListCount);
425 » if (m_pListContent) 367
426 » » m_pListContent->Move(GetClientRect(), TRUE, FALSE); 368 PWL_CREATEPARAM ccp = cp;
427 } 369 ccp.pParentWnd = this;
428 370 ccp.dwFlags = PWS_CHILD | PWS_VISIBLE;
429 void CPWL_IconList::CreateChildWnd(const PWL_CREATEPARAM & cp) 371 m_pListContent->Create(ccp);
430 { 372 }
431 » m_pListContent = new CPWL_IconList_Content(m_nListCount); 373
432 374 void CPWL_IconList::OnCreated() {
433 » PWL_CREATEPARAM ccp = cp; 375 if (CPWL_ScrollBar* pScrollBar = GetVScrollBar()) {
434 » ccp.pParentWnd = this; 376 pScrollBar->RemoveFlag(PWS_AUTOTRANSPARENT);
435 » ccp.dwFlags = PWS_CHILD | PWS_VISIBLE; 377 pScrollBar->SetTransparency(255);
436 » m_pListContent->Create(ccp); 378 pScrollBar->SetNotifyForever(TRUE);
437 } 379 }
438 380 }
439 void CPWL_IconList::OnCreated() 381
440 { 382 void CPWL_IconList::OnNotify(CPWL_Wnd* pWnd,
441 » if (CPWL_ScrollBar* pScrollBar = GetVScrollBar()) 383 FX_DWORD msg,
442 » { 384 intptr_t wParam,
443 » » pScrollBar->RemoveFlag(PWS_AUTOTRANSPARENT); 385 intptr_t lParam) {
444 » » pScrollBar->SetTransparency(255); 386 CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam);
445 » » pScrollBar->SetNotifyForever(TRUE); 387
446 » } 388 if (wParam == SBT_VSCROLL) {
447 } 389 switch (msg) {
448 390 case PNM_SETSCROLLINFO:
449 void CPWL_IconList::OnNotify(CPWL_Wnd* pWnd, FX_DWORD msg, intptr_t wParam, intp tr_t lParam) 391 if (PWL_SCROLL_INFO* pInfo = (PWL_SCROLL_INFO*)lParam) {
450 { 392 if (CPWL_ScrollBar* pScrollBar = GetVScrollBar()) {
451 » CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam); 393 if (pInfo->fContentMax - pInfo->fContentMin > pInfo->fPlateWidth) {
452 394 if (!pScrollBar->IsVisible()) {
453 » if (wParam == SBT_VSCROLL) 395 pScrollBar->SetVisible(TRUE);
454 » { 396 RePosChildWnd();
455 » » switch (msg) 397 } else {
456 » » { 398 }
457 » » case PNM_SETSCROLLINFO: 399 } else {
458 » » » if (PWL_SCROLL_INFO* pInfo = (PWL_SCROLL_INFO*)lParam) 400 if (pScrollBar->IsVisible()) {
459 » » » { 401 pScrollBar->SetVisible(FALSE);
460 » » » » if (CPWL_ScrollBar* pScrollBar = GetVScrollBar() ) 402 RePosChildWnd();
461 » » » » { 403 }
462 » » » » » if (pInfo->fContentMax - pInfo->fContent Min > pInfo->fPlateWidth) 404
463 » » » » » { 405 if (m_pListContent)
464 » » » » » » if (!pScrollBar->IsVisible()) 406 m_pListContent->SetScrollPos(CPDF_Point(0.0f, 0.0f));
465 » » » » » » { 407 }
466 » » » » » » » pScrollBar->SetVisible(T RUE); 408
467 » » » » » » » RePosChildWnd(); 409 pScrollBar->OnNotify(pWnd, PNM_SETSCROLLINFO, wParam, lParam);
468 » » » » » » } 410 }
469 » » » » » » else 411 }
470 » » » » » » { 412 return;
471 » » » » » » } 413 case PNM_SCROLLWINDOW:
472 » » » » » } 414 if (m_pListContent) {
473 » » » » » else 415 m_pListContent->SetScrollPos(CPDF_Point(0.0f, *(FX_FLOAT*)lParam));
474 » » » » » { 416 m_pListContent->ResetFace();
475 » » » » » » if (pScrollBar->IsVisible()) 417 m_pListContent->InvalidateRect(NULL);
476 » » » » » » { 418 }
477 » » » » » » » pScrollBar->SetVisible(F ALSE); 419 return;
478 » » » » » » » RePosChildWnd(); 420 case PNM_SETSCROLLPOS:
479 » » » » » » } 421 if (CPWL_ScrollBar* pScrollBar = GetVScrollBar())
480 422 pScrollBar->OnNotify(pWnd, PNM_SETSCROLLPOS, wParam, lParam);
481 » » » » » » if (m_pListContent) 423 return;
482 » » » » » » » m_pListContent->SetScrol lPos(CPDF_Point(0.0f,0.0f)); 424 }
483 » » » » » } 425 }
484 426 }
485 » » » » » pScrollBar->OnNotify(pWnd,PNM_SETSCROLLI NFO,wParam,lParam); 427
486 » » » » } 428 void CPWL_IconList::SetSelect(int32_t nIndex) {
487 » » » } 429 m_pListContent->SetSelect(nIndex);
488 » » » return; 430 }
489 » » case PNM_SCROLLWINDOW: 431
490 » » » if (m_pListContent) 432 void CPWL_IconList::SetTopItem(int32_t nIndex) {
491 » » » { 433 m_pListContent->ScrollToItem(nIndex);
492 » » » » m_pListContent->SetScrollPos(CPDF_Point(0.0f, *( FX_FLOAT*)lParam)); 434 }
493 » » » » m_pListContent->ResetFace(); 435
494 » » » » m_pListContent->InvalidateRect(NULL); 436 int32_t CPWL_IconList::GetSelect() const {
495 » » » } 437 return m_pListContent->GetSelect();
496 » » » return; 438 }
497 » » case PNM_SETSCROLLPOS: 439
498 » » » if (CPWL_ScrollBar* pScrollBar = GetVScrollBar()) 440 void CPWL_IconList::SetNotify(IPWL_IconList_Notify* pNotify) {
499 » » » » pScrollBar->OnNotify(pWnd,PNM_SETSCROLLPOS,wPara m,lParam); 441 m_pListContent->SetNotify(pNotify);
500 » » » return; 442 }
501 » » } 443
502 » } 444 void CPWL_IconList::EnableNotify(FX_BOOL bNotify) {
503 } 445 m_pListContent->EnableNotify(bNotify);
504 446 }
505 void CPWL_IconList::SetSelect(int32_t nIndex) 447
506 { 448 void CPWL_IconList::SetListData(int32_t nItemIndex, void* pData) {
507 » m_pListContent->SetSelect(nIndex); 449 m_pListContent->SetListData(nItemIndex, pData);
508 } 450 }
509 451
510 void CPWL_IconList::SetTopItem(int32_t nIndex) 452 void CPWL_IconList::SetListIcon(int32_t nItemIndex, int32_t nIconIndex) {
511 { 453 m_pListContent->SetListIcon(nItemIndex, nIconIndex);
512 » m_pListContent->ScrollToItem(nIndex); 454 }
513 } 455
514 456 void CPWL_IconList::SetListString(int32_t nItemIndex,
515 int32_t CPWL_IconList::GetSelect() const 457 const CFX_WideString& str) {
516 { 458 m_pListContent->SetListString(nItemIndex, str);
517 » return m_pListContent->GetSelect(); 459 }
518 } 460
519 461 CFX_WideString CPWL_IconList::GetListString(int32_t nItemIndex) const {
520 void CPWL_IconList::SetNotify(IPWL_IconList_Notify* pNotify) 462 return m_pListContent->GetListString(nItemIndex);
521 { 463 }
522 » m_pListContent->SetNotify(pNotify); 464
523 } 465 void CPWL_IconList::SetIconFillColor(const CPWL_Color& color) {
524 466 m_pListContent->SetIconFillColor(color);
525 void CPWL_IconList::EnableNotify(FX_BOOL bNotify) 467 }
526 { 468
527 » m_pListContent->EnableNotify(bNotify); 469 FX_BOOL CPWL_IconList::OnMouseWheel(short zDelta,
528 } 470 const CPDF_Point& point,
529 471 FX_DWORD nFlag) {
530 void CPWL_IconList::SetListData(int32_t nItemIndex, void* pData) 472 CPDF_Point ptScroll = m_pListContent->GetScrollPos();
531 { 473 CPDF_Rect rcScroll = m_pListContent->GetScrollArea();
532 » m_pListContent->SetListData(nItemIndex, pData); 474 CPDF_Rect rcContents = m_pListContent->GetClientRect();
533 } 475
534 476 if (rcScroll.top - rcScroll.bottom > rcContents.Height()) {
535 void CPWL_IconList::SetListIcon(int32_t nItemIndex, int32_t nIconIndex) 477 CPDF_Point ptNew = ptScroll;
536 { 478
537 » m_pListContent->SetListIcon(nItemIndex, nIconIndex); 479 if (zDelta > 0)
538 } 480 ptNew.y += 30;
539 481 else
540 void CPWL_IconList::SetListString(int32_t nItemIndex, const CFX_WideString& str) 482 ptNew.y -= 30;
541 { 483
542 » m_pListContent->SetListString(nItemIndex, str); 484 if (ptNew.y > rcScroll.top)
543 } 485 ptNew.y = rcScroll.top;
544 486 if (ptNew.y < rcScroll.bottom + rcContents.Height())
545 CFX_WideString CPWL_IconList::GetListString(int32_t nItemIndex) const 487 ptNew.y = rcScroll.bottom + rcContents.Height();
546 { 488 if (ptNew.y < rcScroll.bottom)
547 » return m_pListContent->GetListString(nItemIndex); 489 ptNew.y = rcScroll.bottom;
548 } 490
549 491 if (ptNew.y != ptScroll.y) {
550 void CPWL_IconList::SetIconFillColor(const CPWL_Color& color) 492 m_pListContent->SetScrollPos(ptNew);
551 { 493 m_pListContent->ResetFace();
552 » m_pListContent->SetIconFillColor(color); 494 m_pListContent->InvalidateRect(NULL);
553 } 495
554 496 if (CPWL_ScrollBar* pScrollBar = GetVScrollBar())
555 FX_BOOL»CPWL_IconList::OnMouseWheel(short zDelta, const CPDF_Point & point, FX_D WORD nFlag) 497 pScrollBar->OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL,
556 { 498 (intptr_t)&ptNew.y);
557 » CPDF_Point ptScroll = m_pListContent->GetScrollPos(); 499
558 » CPDF_Rect rcScroll = m_pListContent->GetScrollArea(); 500 return TRUE;
559 » CPDF_Rect rcContents = m_pListContent->GetClientRect(); 501 }
560 502 }
561 » if (rcScroll.top - rcScroll.bottom > rcContents.Height()) 503
562 » { 504 return FALSE;
563 » » CPDF_Point ptNew = ptScroll; 505 }
564
565 » » if (zDelta > 0)
566 » » » ptNew.y += 30;
567 » » else
568 » » » ptNew.y -= 30;
569
570 » » if (ptNew.y > rcScroll.top)
571 » » » ptNew.y = rcScroll.top;
572 » » if (ptNew.y < rcScroll.bottom + rcContents.Height())
573 » » » ptNew.y = rcScroll.bottom + rcContents.Height();
574 » » if (ptNew.y < rcScroll.bottom)
575 » » » ptNew.y = rcScroll.bottom;
576
577 » » if (ptNew.y != ptScroll.y)
578 » » {
579 » » » m_pListContent->SetScrollPos(ptNew);
580 » » » m_pListContent->ResetFace();
581 » » » m_pListContent->InvalidateRect(NULL);
582
583 » » » if (CPWL_ScrollBar* pScrollBar = GetVScrollBar())
584 » » » » pScrollBar->OnNotify(this, PNM_SETSCROLLPOS, SBT _VSCROLL, (intptr_t)&ptNew.y);
585
586 » » » return TRUE;
587 » » }
588 » }
589
590 » return FALSE;
591 }
592
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698