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/fxfa/app/xfa_ffcheckbutton.h" | 7 #include "xfa/fxfa/app/xfa_ffcheckbutton.h" |
8 | 8 |
9 #include "xfa/fwl/core/cfwl_checkbox.h" | 9 #include "xfa/fwl/core/cfwl_checkbox.h" |
10 #include "xfa/fwl/core/cfwl_message.h" | 10 #include "xfa/fwl/core/cfwl_message.h" |
11 #include "xfa/fwl/core/cfwl_widgetmgr.h" | 11 #include "xfa/fwl/core/cfwl_widgetmgr.h" |
12 #include "xfa/fwl/core/fwl_noteimp.h" | 12 #include "xfa/fwl/core/fwl_noteimp.h" |
13 #include "xfa/fxfa/app/xfa_ffexclgroup.h" | 13 #include "xfa/fxfa/app/xfa_ffexclgroup.h" |
14 #include "xfa/fxfa/app/xfa_fffield.h" | 14 #include "xfa/fxfa/app/xfa_fffield.h" |
15 #include "xfa/fxfa/xfa_ffapp.h" | 15 #include "xfa/fxfa/xfa_ffapp.h" |
16 #include "xfa/fxfa/xfa_ffdoc.h" | 16 #include "xfa/fxfa/xfa_ffdoc.h" |
17 #include "xfa/fxfa/xfa_ffdocview.h" | 17 #include "xfa/fxfa/xfa_ffdocview.h" |
18 #include "xfa/fxfa/xfa_ffpageview.h" | 18 #include "xfa/fxfa/xfa_ffpageview.h" |
19 #include "xfa/fxfa/xfa_ffwidget.h" | 19 #include "xfa/fxfa/xfa_ffwidget.h" |
20 | 20 |
21 CXFA_FFCheckButton::CXFA_FFCheckButton(CXFA_FFPageView* pPageView, | 21 CXFA_FFCheckButton::CXFA_FFCheckButton(CXFA_FFPageView* pPageView, |
22 CXFA_WidgetAcc* pDataAcc) | 22 CXFA_WidgetAcc* pDataAcc) |
23 : CXFA_FFField(pPageView, pDataAcc), m_pOldDelegate(nullptr) { | 23 : CXFA_FFField(pPageView, pDataAcc), m_pOldDelegate(nullptr) { |
24 m_rtCheckBox.Set(0, 0, 0, 0); | 24 m_rtCheckBox.Set(0, 0, 0, 0); |
25 } | 25 } |
26 | 26 |
27 CXFA_FFCheckButton::~CXFA_FFCheckButton() {} | 27 CXFA_FFCheckButton::~CXFA_FFCheckButton() {} |
28 | 28 |
29 FX_BOOL CXFA_FFCheckButton::LoadWidget() { | 29 bool CXFA_FFCheckButton::LoadWidget() { |
30 CFWL_CheckBox* pCheckBox = new CFWL_CheckBox(GetFWLApp()); | 30 CFWL_CheckBox* pCheckBox = new CFWL_CheckBox(GetFWLApp()); |
31 pCheckBox->Initialize(); | 31 pCheckBox->Initialize(); |
32 m_pNormalWidget = pCheckBox; | 32 m_pNormalWidget = pCheckBox; |
33 m_pNormalWidget->SetLayoutItem(this); | 33 m_pNormalWidget->SetLayoutItem(this); |
34 | 34 |
35 IFWL_Widget* pWidget = m_pNormalWidget->GetWidget(); | 35 IFWL_Widget* pWidget = m_pNormalWidget->GetWidget(); |
36 CFWL_NoteDriver* pNoteDriver = pWidget->GetOwnerApp()->GetNoteDriver(); | 36 CFWL_NoteDriver* pNoteDriver = pWidget->GetOwnerApp()->GetNoteDriver(); |
37 pNoteDriver->RegisterEventTarget(pWidget, pWidget); | 37 pNoteDriver->RegisterEventTarget(pWidget, pWidget); |
38 | 38 |
39 m_pOldDelegate = m_pNormalWidget->GetDelegate(); | 39 m_pOldDelegate = m_pNormalWidget->GetDelegate(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 dwStyleEx = FWL_STYLEEXT_CKB_SignShapeCircle; | 81 dwStyleEx = FWL_STYLEEXT_CKB_SignShapeCircle; |
82 } | 82 } |
83 } break; | 83 } break; |
84 } | 84 } |
85 if (m_pDataAcc->IsAllowNeutral()) { | 85 if (m_pDataAcc->IsAllowNeutral()) { |
86 dwStyleEx |= FWL_STYLEEXT_CKB_3State; | 86 dwStyleEx |= FWL_STYLEEXT_CKB_3State; |
87 } | 87 } |
88 pCheckBox->ModifyStylesEx( | 88 pCheckBox->ModifyStylesEx( |
89 dwStyleEx, FWL_STYLEEXT_CKB_SignShapeMask | FWL_STYLEEXT_CKB_3State); | 89 dwStyleEx, FWL_STYLEEXT_CKB_SignShapeMask | FWL_STYLEEXT_CKB_3State); |
90 } | 90 } |
91 FX_BOOL CXFA_FFCheckButton::PerformLayout() { | 91 bool CXFA_FFCheckButton::PerformLayout() { |
92 CXFA_FFWidget::PerformLayout(); | 92 CXFA_FFWidget::PerformLayout(); |
93 FX_FLOAT fCheckSize = m_pDataAcc->GetCheckButtonSize(); | 93 FX_FLOAT fCheckSize = m_pDataAcc->GetCheckButtonSize(); |
94 CXFA_Margin mgWidget = m_pDataAcc->GetMargin(); | 94 CXFA_Margin mgWidget = m_pDataAcc->GetMargin(); |
95 CFX_RectF rtWidget; | 95 CFX_RectF rtWidget; |
96 GetRectWithoutRotate(rtWidget); | 96 GetRectWithoutRotate(rtWidget); |
97 if (mgWidget) { | 97 if (mgWidget) { |
98 XFA_RectWidthoutMargin(rtWidget, mgWidget); | 98 XFA_RectWidthoutMargin(rtWidget, mgWidget); |
99 } | 99 } |
100 int32_t iCapPlacement = -1; | 100 int32_t iCapPlacement = -1; |
101 FX_FLOAT fCapReserve = 0; | 101 FX_FLOAT fCapReserve = 0; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 if (margin) { | 173 if (margin) { |
174 XFA_RectWidthoutMargin(m_rtUI, margin); | 174 XFA_RectWidthoutMargin(m_rtUI, margin); |
175 } | 175 } |
176 } | 176 } |
177 m_rtUI.Normalize(); | 177 m_rtUI.Normalize(); |
178 LayoutCaption(); | 178 LayoutCaption(); |
179 SetFWLRect(); | 179 SetFWLRect(); |
180 if (m_pNormalWidget) { | 180 if (m_pNormalWidget) { |
181 m_pNormalWidget->Update(); | 181 m_pNormalWidget->Update(); |
182 } | 182 } |
183 return TRUE; | 183 return true; |
184 } | 184 } |
185 void CXFA_FFCheckButton::CapLeftRightPlacement(CXFA_Margin mgCap) { | 185 void CXFA_FFCheckButton::CapLeftRightPlacement(CXFA_Margin mgCap) { |
186 XFA_RectWidthoutMargin(m_rtCaption, mgCap); | 186 XFA_RectWidthoutMargin(m_rtCaption, mgCap); |
187 if (m_rtCaption.height < 0) { | 187 if (m_rtCaption.height < 0) { |
188 m_rtCaption.top += m_rtCaption.height; | 188 m_rtCaption.top += m_rtCaption.height; |
189 } | 189 } |
190 if (m_rtCaption.width < 0) { | 190 if (m_rtCaption.width < 0) { |
191 m_rtCaption.left += m_rtCaption.width; | 191 m_rtCaption.left += m_rtCaption.width; |
192 m_rtCaption.width = -m_rtCaption.width; | 192 m_rtCaption.width = -m_rtCaption.width; |
193 } | 193 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 : 0); | 234 : 0); |
235 RenderCaption(pGS, &mtRotate); | 235 RenderCaption(pGS, &mtRotate); |
236 DrawHighlight(pGS, &mtRotate, dwStatus, | 236 DrawHighlight(pGS, &mtRotate, dwStatus, |
237 m_pDataAcc->GetCheckButtonShape() == XFA_ATTRIBUTEENUM_Round); | 237 m_pDataAcc->GetCheckButtonShape() == XFA_ATTRIBUTEENUM_Round); |
238 CFX_Matrix mt; | 238 CFX_Matrix mt; |
239 mt.Set(1, 0, 0, 1, m_rtCheckBox.left, m_rtCheckBox.top); | 239 mt.Set(1, 0, 0, 1, m_rtCheckBox.left, m_rtCheckBox.top); |
240 mt.Concat(mtRotate); | 240 mt.Concat(mtRotate); |
241 GetApp()->GetWidgetMgrDelegate()->OnDrawWidget(m_pNormalWidget->GetWidget(), | 241 GetApp()->GetWidgetMgrDelegate()->OnDrawWidget(m_pNormalWidget->GetWidget(), |
242 pGS, &mt); | 242 pGS, &mt); |
243 } | 243 } |
244 FX_BOOL CXFA_FFCheckButton::OnLButtonUp(uint32_t dwFlags, | 244 bool CXFA_FFCheckButton::OnLButtonUp(uint32_t dwFlags, |
245 FX_FLOAT fx, | 245 FX_FLOAT fx, |
246 FX_FLOAT fy) { | 246 FX_FLOAT fy) { |
247 if (!m_pNormalWidget || !IsButtonDown()) | 247 if (!m_pNormalWidget || !IsButtonDown()) |
248 return FALSE; | 248 return false; |
249 | 249 |
250 SetButtonDown(FALSE); | 250 SetButtonDown(false); |
251 CFWL_MsgMouse ms; | 251 CFWL_MsgMouse ms; |
252 ms.m_dwCmd = FWL_MouseCommand::LeftButtonUp; | 252 ms.m_dwCmd = FWL_MouseCommand::LeftButtonUp; |
253 ms.m_dwFlags = dwFlags; | 253 ms.m_dwFlags = dwFlags; |
254 ms.m_fx = fx; | 254 ms.m_fx = fx; |
255 ms.m_fy = fy; | 255 ms.m_fy = fy; |
256 FWLToClient(ms.m_fx, ms.m_fy); | 256 FWLToClient(ms.m_fx, ms.m_fy); |
257 ms.m_pDstTarget = m_pNormalWidget->GetWidget(); | 257 ms.m_pDstTarget = m_pNormalWidget->GetWidget(); |
258 TranslateFWLMessage(&ms); | 258 TranslateFWLMessage(&ms); |
259 return TRUE; | 259 return true; |
260 } | 260 } |
261 | 261 |
262 XFA_CHECKSTATE CXFA_FFCheckButton::FWLState2XFAState() { | 262 XFA_CHECKSTATE CXFA_FFCheckButton::FWLState2XFAState() { |
263 uint32_t dwState = m_pNormalWidget->GetStates(); | 263 uint32_t dwState = m_pNormalWidget->GetStates(); |
264 if (dwState & FWL_STATE_CKB_Checked) | 264 if (dwState & FWL_STATE_CKB_Checked) |
265 return XFA_CHECKSTATE_On; | 265 return XFA_CHECKSTATE_On; |
266 if (dwState & FWL_STATE_CKB_Neutral) | 266 if (dwState & FWL_STATE_CKB_Neutral) |
267 return XFA_CHECKSTATE_Neutral; | 267 return XFA_CHECKSTATE_Neutral; |
268 return XFA_CHECKSTATE_Off; | 268 return XFA_CHECKSTATE_Off; |
269 } | 269 } |
270 | 270 |
271 FX_BOOL CXFA_FFCheckButton::CommitData() { | 271 bool CXFA_FFCheckButton::CommitData() { |
272 XFA_CHECKSTATE eCheckState = FWLState2XFAState(); | 272 XFA_CHECKSTATE eCheckState = FWLState2XFAState(); |
273 m_pDataAcc->SetCheckState(eCheckState, true); | 273 m_pDataAcc->SetCheckState(eCheckState, true); |
274 return TRUE; | 274 return true; |
275 } | 275 } |
276 | 276 |
277 FX_BOOL CXFA_FFCheckButton::IsDataChanged() { | 277 bool CXFA_FFCheckButton::IsDataChanged() { |
278 XFA_CHECKSTATE eCheckState = FWLState2XFAState(); | 278 XFA_CHECKSTATE eCheckState = FWLState2XFAState(); |
279 return m_pDataAcc->GetCheckState() != eCheckState; | 279 return m_pDataAcc->GetCheckState() != eCheckState; |
280 } | 280 } |
281 void CXFA_FFCheckButton::SetFWLCheckState(XFA_CHECKSTATE eCheckState) { | 281 void CXFA_FFCheckButton::SetFWLCheckState(XFA_CHECKSTATE eCheckState) { |
282 if (eCheckState == XFA_CHECKSTATE_Neutral) { | 282 if (eCheckState == XFA_CHECKSTATE_Neutral) { |
283 m_pNormalWidget->SetStates(FWL_STATE_CKB_Neutral, TRUE); | 283 m_pNormalWidget->SetStates(FWL_STATE_CKB_Neutral, true); |
284 } else { | 284 } else { |
285 m_pNormalWidget->SetStates(FWL_STATE_CKB_Checked, | 285 m_pNormalWidget->SetStates(FWL_STATE_CKB_Checked, |
286 eCheckState == XFA_CHECKSTATE_On); | 286 eCheckState == XFA_CHECKSTATE_On); |
287 } | 287 } |
288 } | 288 } |
289 FX_BOOL CXFA_FFCheckButton::UpdateFWLData() { | 289 bool CXFA_FFCheckButton::UpdateFWLData() { |
290 if (!m_pNormalWidget) { | 290 if (!m_pNormalWidget) { |
291 return FALSE; | 291 return false; |
292 } | 292 } |
293 XFA_CHECKSTATE eState = m_pDataAcc->GetCheckState(); | 293 XFA_CHECKSTATE eState = m_pDataAcc->GetCheckState(); |
294 SetFWLCheckState(eState); | 294 SetFWLCheckState(eState); |
295 m_pNormalWidget->Update(); | 295 m_pNormalWidget->Update(); |
296 return TRUE; | 296 return true; |
297 } | 297 } |
298 | 298 |
299 void CXFA_FFCheckButton::OnProcessMessage(CFWL_Message* pMessage) { | 299 void CXFA_FFCheckButton::OnProcessMessage(CFWL_Message* pMessage) { |
300 m_pOldDelegate->OnProcessMessage(pMessage); | 300 m_pOldDelegate->OnProcessMessage(pMessage); |
301 } | 301 } |
302 | 302 |
303 void CXFA_FFCheckButton::OnProcessEvent(CFWL_Event* pEvent) { | 303 void CXFA_FFCheckButton::OnProcessEvent(CFWL_Event* pEvent) { |
304 CXFA_FFField::OnProcessEvent(pEvent); | 304 CXFA_FFField::OnProcessEvent(pEvent); |
305 switch (pEvent->GetClassID()) { | 305 switch (pEvent->GetClassID()) { |
306 case CFWL_EventType::CheckStateChanged: { | 306 case CFWL_EventType::CheckStateChanged: { |
(...skipping 24 matching lines...) Expand all Loading... |
331 default: | 331 default: |
332 break; | 332 break; |
333 } | 333 } |
334 m_pOldDelegate->OnProcessEvent(pEvent); | 334 m_pOldDelegate->OnProcessEvent(pEvent); |
335 } | 335 } |
336 | 336 |
337 void CXFA_FFCheckButton::OnDrawWidget(CFX_Graphics* pGraphics, | 337 void CXFA_FFCheckButton::OnDrawWidget(CFX_Graphics* pGraphics, |
338 const CFX_Matrix* pMatrix) { | 338 const CFX_Matrix* pMatrix) { |
339 m_pOldDelegate->OnDrawWidget(pGraphics, pMatrix); | 339 m_pOldDelegate->OnDrawWidget(pGraphics, pMatrix); |
340 } | 340 } |
OLD | NEW |