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 "../../include/formfiller/FormFiller.h"
8 #include "../../include/formfiller/FFL_FormFiller.h"
9 #include "../../include/formfiller/FFL_RadioButton.h"
10 //#include "../include/FFL_Undo.h"
11
12 /* ------------------------------- CFFL_RadioButton ------------------------------- */
13
CFFL_RadioButton(CPDFDoc_Environment * pApp,CPDFSDK_Annot * pWidget)14 CFFL_RadioButton::CFFL_RadioButton(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pWidget) :
15 CFFL_Button(pApp, pWidget)
16 {
17 }
18
~CFFL_RadioButton()19 CFFL_RadioButton::~CFFL_RadioButton()
20 {
21 }
22
NewPDFWindow(const PWL_CREATEPARAM & cp,CPDFSDK_PageView * pPageView)23 CPWL_Wnd* CFFL_RadioButton::NewPDFWindow(const PWL_CREATEPARAM& cp, CPDFSDK_PageView* pPageView)
24 {
25 CPWL_RadioButton* pWnd = new CPWL_RadioButton();
26 pWnd->Create(cp);
27
28 ASSERT(m_pWidget != NULL);
29 pWnd->SetCheck(m_pWidget->IsChecked());
30
31 return pWnd;
32 }
33
OnKeyDown(CPDFSDK_Annot * pAnnot,FX_UINT nKeyCode,FX_UINT nFlags)34 FX_BOOL CFFL_RadioButton::OnKeyDown(CPDFSDK_Annot* pAnnot, FX_UINT nKeyCode, FX_UINT nFlags)
35 {
36 switch (nKeyCode)
37 {
38 case FWL_VKEY_Return:
39 case FWL_VKEY_Space:
40 return TRUE;
41 default:
42 return CFFL_FormFiller::OnKeyDown(pAnnot, nKeyCode, nFlags);
43 }
44 }
45
OnChar(CPDFSDK_Annot * pAnnot,FX_UINT nChar,FX_UINT nFlags)46 FX_BOOL CFFL_RadioButton::OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags)
47 {
48 switch (nChar)
49 {
50 case FWL_VKEY_Return:
51 case FWL_VKEY_Space:
52 {
53 CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller();
54 ASSERT(pIFormFiller != NULL);
55
56 CPDFSDK_PageView* pPageView = pAnnot->GetPageView();
57 ASSERT(pPageView != NULL);
58
59 FX_BOOL bReset = FALSE;
60 FX_BOOL bExit = FALSE;
61
62 pIFormFiller->OnButtonUp(m_pWidget, pPageView, bReset, bExit,nFlags);
63
64 if (bReset) return TRUE;
65 if (bExit) return TRUE;
66
67 CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags);
68
69 if (CPWL_RadioButton * pWnd = (CPWL_RadioButton*)GetPDFWindow(pPageView, TRUE))
70 pWnd->SetCheck(TRUE);
71 CommitData(pPageView,nFlags);
72 return TRUE;
73 }
74 default:
75 return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags);
76 }
77 }
78
OnLButtonUp(CPDFSDK_PageView * pPageView,CPDFSDK_Annot * pAnnot,FX_UINT nFlags,const CPDF_Point & point)79 FX_BOOL CFFL_RadioButton::OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point)
80 {
81 CFFL_Button::OnLButtonUp(pPageView, pAnnot, nFlags, point);
82
83 if (IsValid())
84 {
85 if (CPWL_RadioButton * pWnd = (CPWL_RadioButton*)GetPDFWindow(pPageView, TRUE))
86 pWnd->SetCheck(TRUE);
87
88 if (!CommitData(pPageView,nFlags)) return FALSE;
89 }
90
91 return TRUE;
92 }
93
IsDataChanged(CPDFSDK_PageView * pPageView)94 FX_BOOL CFFL_RadioButton::IsDataChanged(CPDFSDK_PageView* pPageView)
95 {
96 ASSERT(m_pWidget != NULL);
97
98 if (CPWL_RadioButton* pWnd = (CPWL_RadioButton*)GetPDFWindow(pPageView, FALSE))
99 {
100 return pWnd->IsChecked() != m_pWidget->IsChecked();
101 }
102
103 return FALSE;
104 }
105
SaveData(CPDFSDK_PageView * pPageView)106 void CFFL_RadioButton::SaveData(CPDFSDK_PageView* pPageView)
107 {
108 ASSERT(m_pWidget != NULL);
109
110 if (CPWL_RadioButton* pWnd = (CPWL_RadioButton*)GetPDFWindow(pPageView, FALSE))
111 {
112
113 FX_BOOL bNewChecked = pWnd->IsChecked();
114
115 if (bNewChecked)
116 {
117 CPDF_FormField* pField = m_pWidget->GetFormField();
118 ASSERT(pField != NULL);
119
120 for (FX_INT32 i=0,sz=pField->CountControls(); i<sz; i++)
121 {
122 if (CPDF_FormControl* pCtrl = pField->GetControl(i))
123 {
124 if (pCtrl->IsChecked())
125 {
126 break;
127 }
128 }
129 }
130 }
131
132 m_pWidget->SetCheck(bNewChecked, FALSE);
133 m_pWidget->UpdateField();
134 SetChangeMark();
135 }
136 }
137
138