OLD | NEW |
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 "xfa/fwl/cfwl_pushbutton.h" | 7 #include "xfa/fwl/cfwl_pushbutton.h" |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 CFWL_Widget::SetStates(dwStates); | 43 CFWL_Widget::SetStates(dwStates); |
44 } | 44 } |
45 | 45 |
46 void CFWL_PushButton::Update() { | 46 void CFWL_PushButton::Update() { |
47 if (IsLocked()) | 47 if (IsLocked()) |
48 return; | 48 return; |
49 if (!m_pProperties->m_pThemeProvider) | 49 if (!m_pProperties->m_pThemeProvider) |
50 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | 50 m_pProperties->m_pThemeProvider = GetAvailableTheme(); |
51 | 51 |
52 UpdateTextOutStyles(); | 52 UpdateTextOutStyles(); |
53 GetClientRect(m_rtClient); | 53 m_rtClient = GetClientRect(); |
54 m_rtCaption = m_rtClient; | 54 m_rtCaption = m_rtClient; |
55 FX_FLOAT* fcaption = | 55 FX_FLOAT* fcaption = |
56 static_cast<FX_FLOAT*>(GetThemeCapacity(CFWL_WidgetCapacity::Margin)); | 56 static_cast<FX_FLOAT*>(GetThemeCapacity(CFWL_WidgetCapacity::Margin)); |
57 m_rtCaption.Inflate(-*fcaption, -*fcaption); | 57 m_rtCaption.Inflate(-*fcaption, -*fcaption); |
58 } | 58 } |
59 | 59 |
60 void CFWL_PushButton::DrawWidget(CFX_Graphics* pGraphics, | 60 void CFWL_PushButton::DrawWidget(CFX_Graphics* pGraphics, |
61 const CFX_Matrix* pMatrix) { | 61 const CFX_Matrix* pMatrix) { |
62 if (!pGraphics) | 62 if (!pGraphics) |
63 return; | 63 return; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 const CFX_Matrix* pMatrix) { | 201 const CFX_Matrix* pMatrix) { |
202 DrawWidget(pGraphics, pMatrix); | 202 DrawWidget(pGraphics, pMatrix); |
203 } | 203 } |
204 | 204 |
205 void CFWL_PushButton::OnFocusChanged(CFWL_Message* pMsg, bool bSet) { | 205 void CFWL_PushButton::OnFocusChanged(CFWL_Message* pMsg, bool bSet) { |
206 if (bSet) | 206 if (bSet) |
207 m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; | 207 m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; |
208 else | 208 else |
209 m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; | 209 m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; |
210 | 210 |
211 Repaint(&m_rtClient); | 211 RepaintRect(m_rtClient); |
212 } | 212 } |
213 | 213 |
214 void CFWL_PushButton::OnLButtonDown(CFWL_MessageMouse* pMsg) { | 214 void CFWL_PushButton::OnLButtonDown(CFWL_MessageMouse* pMsg) { |
215 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) | 215 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) |
216 SetFocus(true); | 216 SetFocus(true); |
217 | 217 |
218 m_bBtnDown = true; | 218 m_bBtnDown = true; |
219 m_pProperties->m_dwStates |= FWL_STATE_PSB_Hovered; | 219 m_pProperties->m_dwStates |= FWL_STATE_PSB_Hovered; |
220 m_pProperties->m_dwStates |= FWL_STATE_PSB_Pressed; | 220 m_pProperties->m_dwStates |= FWL_STATE_PSB_Pressed; |
221 Repaint(&m_rtClient); | 221 RepaintRect(m_rtClient); |
222 } | 222 } |
223 | 223 |
224 void CFWL_PushButton::OnLButtonUp(CFWL_MessageMouse* pMsg) { | 224 void CFWL_PushButton::OnLButtonUp(CFWL_MessageMouse* pMsg) { |
225 m_bBtnDown = false; | 225 m_bBtnDown = false; |
226 if (m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { | 226 if (m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { |
227 m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Pressed; | 227 m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Pressed; |
228 m_pProperties->m_dwStates |= FWL_STATE_PSB_Hovered; | 228 m_pProperties->m_dwStates |= FWL_STATE_PSB_Hovered; |
229 } else { | 229 } else { |
230 m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Hovered; | 230 m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Hovered; |
231 m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Pressed; | 231 m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Pressed; |
232 } | 232 } |
233 if (m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { | 233 if (m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { |
234 CFWL_Event wmClick(CFWL_Event::Type::Click, this); | 234 CFWL_Event wmClick(CFWL_Event::Type::Click, this); |
235 DispatchEvent(&wmClick); | 235 DispatchEvent(&wmClick); |
236 } | 236 } |
237 Repaint(&m_rtClient); | 237 RepaintRect(m_rtClient); |
238 } | 238 } |
239 | 239 |
240 void CFWL_PushButton::OnMouseMove(CFWL_MessageMouse* pMsg) { | 240 void CFWL_PushButton::OnMouseMove(CFWL_MessageMouse* pMsg) { |
241 bool bRepaint = false; | 241 bool bRepaint = false; |
242 if (m_bBtnDown) { | 242 if (m_bBtnDown) { |
243 if (m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { | 243 if (m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { |
244 if ((m_pProperties->m_dwStates & FWL_STATE_PSB_Pressed) == 0) { | 244 if ((m_pProperties->m_dwStates & FWL_STATE_PSB_Pressed) == 0) { |
245 m_pProperties->m_dwStates |= FWL_STATE_PSB_Pressed; | 245 m_pProperties->m_dwStates |= FWL_STATE_PSB_Pressed; |
246 bRepaint = true; | 246 bRepaint = true; |
247 } | 247 } |
(...skipping 13 matching lines...) Expand all Loading... |
261 } | 261 } |
262 } else { | 262 } else { |
263 if (!m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) | 263 if (!m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) |
264 return; | 264 return; |
265 if ((m_pProperties->m_dwStates & FWL_STATE_PSB_Hovered) == 0) { | 265 if ((m_pProperties->m_dwStates & FWL_STATE_PSB_Hovered) == 0) { |
266 m_pProperties->m_dwStates |= FWL_STATE_PSB_Hovered; | 266 m_pProperties->m_dwStates |= FWL_STATE_PSB_Hovered; |
267 bRepaint = true; | 267 bRepaint = true; |
268 } | 268 } |
269 } | 269 } |
270 if (bRepaint) | 270 if (bRepaint) |
271 Repaint(&m_rtClient); | 271 RepaintRect(m_rtClient); |
272 } | 272 } |
273 | 273 |
274 void CFWL_PushButton::OnMouseLeave(CFWL_MessageMouse* pMsg) { | 274 void CFWL_PushButton::OnMouseLeave(CFWL_MessageMouse* pMsg) { |
275 m_bBtnDown = false; | 275 m_bBtnDown = false; |
276 m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Hovered; | 276 m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Hovered; |
277 m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Pressed; | 277 m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Pressed; |
278 Repaint(&m_rtClient); | 278 RepaintRect(m_rtClient); |
279 } | 279 } |
280 | 280 |
281 void CFWL_PushButton::OnKeyDown(CFWL_MessageKey* pMsg) { | 281 void CFWL_PushButton::OnKeyDown(CFWL_MessageKey* pMsg) { |
282 if (pMsg->m_dwKeyCode != FWL_VKEY_Return) | 282 if (pMsg->m_dwKeyCode != FWL_VKEY_Return) |
283 return; | 283 return; |
284 | 284 |
285 CFWL_EventMouse wmMouse(this); | 285 CFWL_EventMouse wmMouse(this); |
286 wmMouse.m_dwCmd = FWL_MouseCommand::LeftButtonUp; | 286 wmMouse.m_dwCmd = FWL_MouseCommand::LeftButtonUp; |
287 DispatchEvent(&wmMouse); | 287 DispatchEvent(&wmMouse); |
288 | 288 |
289 CFWL_Event wmClick(CFWL_Event::Type::Click, this); | 289 CFWL_Event wmClick(CFWL_Event::Type::Click, this); |
290 DispatchEvent(&wmClick); | 290 DispatchEvent(&wmClick); |
291 } | 291 } |
OLD | NEW |