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: xfa/fwl/core/cfwl_combolist.cpp

Issue 2559173002: Move xfa/fwl/core to xfa/fwl. (Closed)
Patch Set: Created 4 years 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 | « xfa/fwl/core/cfwl_combolist.h ('k') | xfa/fwl/core/cfwl_datetimeedit.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 2016 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 "xfa/fwl/core/cfwl_combolist.h"
8
9 #include <memory>
10 #include <utility>
11
12 #include "third_party/base/ptr_util.h"
13 #include "xfa/fwl/core/cfwl_combobox.h"
14 #include "xfa/fwl/core/cfwl_comboedit.h"
15 #include "xfa/fwl/core/cfwl_listbox.h"
16 #include "xfa/fwl/core/cfwl_msgkey.h"
17 #include "xfa/fwl/core/cfwl_msgkillfocus.h"
18 #include "xfa/fwl/core/cfwl_msgmouse.h"
19
20 CFWL_ComboList::CFWL_ComboList(
21 const CFWL_App* app,
22 std::unique_ptr<CFWL_WidgetProperties> properties,
23 CFWL_Widget* pOuter)
24 : CFWL_ListBox(app, std::move(properties), pOuter), m_bNotifyOwner(true) {
25 ASSERT(pOuter);
26 }
27
28 int32_t CFWL_ComboList::MatchItem(const CFX_WideString& wsMatch) {
29 if (wsMatch.IsEmpty())
30 return -1;
31
32 int32_t iCount = CountItems(this);
33 for (int32_t i = 0; i < iCount; i++) {
34 CFWL_ListItem* hItem = GetItem(this, i);
35 CFX_WideString wsText = GetItemText(this, hItem);
36 FX_STRSIZE pos = wsText.Find(wsMatch.c_str());
37 if (!pos)
38 return i;
39 }
40 return -1;
41 }
42
43 void CFWL_ComboList::ChangeSelected(int32_t iSel) {
44 CFWL_ListItem* hItem = GetItem(this, iSel);
45 CFX_RectF rtInvalidate;
46 rtInvalidate.Reset();
47 CFWL_ListItem* hOld = GetSelItem(0);
48 int32_t iOld = GetItemIndex(this, hOld);
49 if (iOld == iSel)
50 return;
51 if (iOld > -1) {
52 CFWL_ListItem* hItem = GetItem(this, iOld);
53 GetItemRect(this, hItem, rtInvalidate);
54 SetSelItem(hOld, false);
55 }
56 if (hItem) {
57 CFX_RectF rect;
58 CFWL_ListItem* hItem = GetItem(this, iSel);
59 GetItemRect(this, hItem, rect);
60 rtInvalidate.Union(rect);
61 CFWL_ListItem* hSel = GetItem(this, iSel);
62 SetSelItem(hSel, true);
63 }
64 if (!rtInvalidate.IsEmpty())
65 Repaint(&rtInvalidate);
66 }
67
68 void CFWL_ComboList::ClientToOuter(FX_FLOAT& fx, FX_FLOAT& fy) {
69 fx += m_pProperties->m_rtWidget.left, fy += m_pProperties->m_rtWidget.top;
70 CFWL_Widget* pOwner = GetOwner();
71 if (!pOwner)
72 return;
73 pOwner->TransformTo(m_pOuter, fx, fy);
74 }
75
76 void CFWL_ComboList::OnProcessMessage(CFWL_Message* pMessage) {
77 if (!pMessage)
78 return;
79
80 CFWL_Message::Type type = pMessage->GetType();
81 bool backDefault = true;
82 if (type == CFWL_Message::Type::SetFocus ||
83 type == CFWL_Message::Type::KillFocus) {
84 OnDropListFocusChanged(pMessage, type == CFWL_Message::Type::SetFocus);
85 } else if (type == CFWL_Message::Type::Mouse) {
86 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage);
87 CFWL_ScrollBar* vertSB = GetVertScrollBar();
88 if (IsShowScrollBar(true) && vertSB) {
89 CFX_RectF rect = vertSB->GetWidgetRect();
90 if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) {
91 pMsg->m_fx -= rect.left;
92 pMsg->m_fy -= rect.top;
93 vertSB->GetDelegate()->OnProcessMessage(pMsg);
94 return;
95 }
96 }
97 switch (pMsg->m_dwCmd) {
98 case FWL_MouseCommand::Move: {
99 backDefault = false;
100 OnDropListMouseMove(pMsg);
101 break;
102 }
103 case FWL_MouseCommand::LeftButtonDown: {
104 backDefault = false;
105 OnDropListLButtonDown(pMsg);
106 break;
107 }
108 case FWL_MouseCommand::LeftButtonUp: {
109 backDefault = false;
110 OnDropListLButtonUp(pMsg);
111 break;
112 }
113 default:
114 break;
115 }
116 } else if (type == CFWL_Message::Type::Key) {
117 backDefault = !OnDropListKey(static_cast<CFWL_MsgKey*>(pMessage));
118 }
119 if (backDefault)
120 CFWL_ListBox::OnProcessMessage(pMessage);
121 }
122
123 void CFWL_ComboList::OnDropListFocusChanged(CFWL_Message* pMsg, bool bSet) {
124 if (bSet)
125 return;
126
127 CFWL_MsgKillFocus* pKill = static_cast<CFWL_MsgKillFocus*>(pMsg);
128 CFWL_ComboBox* pOuter = static_cast<CFWL_ComboBox*>(m_pOuter);
129 if (pKill->m_pSetFocus == m_pOuter ||
130 pKill->m_pSetFocus == pOuter->GetComboEdit()) {
131 pOuter->ShowDropList(false);
132 }
133 }
134
135 void CFWL_ComboList::OnDropListMouseMove(CFWL_MsgMouse* pMsg) {
136 if (GetRTClient().Contains(pMsg->m_fx, pMsg->m_fy)) {
137 if (m_bNotifyOwner)
138 m_bNotifyOwner = false;
139
140 CFWL_ScrollBar* vertSB = GetVertScrollBar();
141 if (IsShowScrollBar(true) && vertSB) {
142 CFX_RectF rect = vertSB->GetWidgetRect();
143 if (rect.Contains(pMsg->m_fx, pMsg->m_fy))
144 return;
145 }
146
147 CFWL_ListItem* hItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy);
148 if (!hItem)
149 return;
150
151 ChangeSelected(GetItemIndex(this, hItem));
152 } else if (m_bNotifyOwner) {
153 ClientToOuter(pMsg->m_fx, pMsg->m_fy);
154 CFWL_ComboBox* pOuter = static_cast<CFWL_ComboBox*>(m_pOuter);
155 pOuter->GetDelegate()->OnProcessMessage(pMsg);
156 }
157 }
158
159 void CFWL_ComboList::OnDropListLButtonDown(CFWL_MsgMouse* pMsg) {
160 if (GetRTClient().Contains(pMsg->m_fx, pMsg->m_fy))
161 return;
162
163 CFWL_ComboBox* pOuter = static_cast<CFWL_ComboBox*>(m_pOuter);
164 pOuter->ShowDropList(false);
165 }
166
167 void CFWL_ComboList::OnDropListLButtonUp(CFWL_MsgMouse* pMsg) {
168 CFWL_ComboBox* pOuter = static_cast<CFWL_ComboBox*>(m_pOuter);
169 if (m_bNotifyOwner) {
170 ClientToOuter(pMsg->m_fx, pMsg->m_fy);
171 pOuter->GetDelegate()->OnProcessMessage(pMsg);
172 return;
173 }
174
175 CFWL_ScrollBar* vertSB = GetVertScrollBar();
176 if (IsShowScrollBar(true) && vertSB) {
177 CFX_RectF rect = vertSB->GetWidgetRect();
178 if (rect.Contains(pMsg->m_fx, pMsg->m_fy))
179 return;
180 }
181 pOuter->ShowDropList(false);
182
183 CFWL_ListItem* hItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy);
184 if (hItem)
185 pOuter->ProcessSelChanged(true);
186 }
187
188 bool CFWL_ComboList::OnDropListKey(CFWL_MsgKey* pKey) {
189 CFWL_ComboBox* pOuter = static_cast<CFWL_ComboBox*>(m_pOuter);
190 bool bPropagate = false;
191 if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) {
192 uint32_t dwKeyCode = pKey->m_dwKeyCode;
193 switch (dwKeyCode) {
194 case FWL_VKEY_Return:
195 case FWL_VKEY_Escape: {
196 pOuter->ShowDropList(false);
197 return true;
198 }
199 case FWL_VKEY_Up:
200 case FWL_VKEY_Down: {
201 OnDropListKeyDown(pKey);
202 pOuter->ProcessSelChanged(false);
203 return true;
204 }
205 default: {
206 bPropagate = true;
207 break;
208 }
209 }
210 } else if (pKey->m_dwCmd == FWL_KeyCommand::Char) {
211 bPropagate = true;
212 }
213 if (bPropagate) {
214 pKey->m_pDstTarget = m_pOuter;
215 pOuter->GetDelegate()->OnProcessMessage(pKey);
216 return true;
217 }
218 return false;
219 }
220
221 void CFWL_ComboList::OnDropListKeyDown(CFWL_MsgKey* pKey) {
222 uint32_t dwKeyCode = pKey->m_dwKeyCode;
223 switch (dwKeyCode) {
224 case FWL_VKEY_Up:
225 case FWL_VKEY_Down:
226 case FWL_VKEY_Home:
227 case FWL_VKEY_End: {
228 CFWL_ComboBox* pOuter = static_cast<CFWL_ComboBox*>(m_pOuter);
229 CFWL_ListItem* hItem = GetItem(this, pOuter->GetCurrentSelection());
230 hItem = GetListItem(hItem, dwKeyCode);
231 if (!hItem)
232 break;
233
234 SetSelection(hItem, hItem, true);
235 ScrollToVisible(hItem);
236 CFX_RectF rtInvalidate;
237 rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width,
238 m_pProperties->m_rtWidget.height);
239 Repaint(&rtInvalidate);
240 break;
241 }
242 default:
243 break;
244 }
245 }
OLDNEW
« no previous file with comments | « xfa/fwl/core/cfwl_combolist.h ('k') | xfa/fwl/core/cfwl_datetimeedit.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698