OLD | NEW |
| (Empty) |
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 "xfa/src/fxfa/app/xfa_ffpushbutton.h" | |
8 | |
9 #include "xfa/include/fwl/core/fwl_widgetmgr.h" | |
10 #include "xfa/include/fwl/lightwidget/pushbutton.h" | |
11 #include "xfa/src/fxfa/app/xfa_ffapp.h" | |
12 #include "xfa/src/fxfa/app/xfa_fffield.h" | |
13 #include "xfa/src/fxfa/app/xfa_ffpageview.h" | |
14 #include "xfa/src/fxfa/app/xfa_ffwidget.h" | |
15 #include "xfa/src/fxfa/app/xfa_ffwidgetacc.h" | |
16 #include "xfa/src/fxfa/app/xfa_textlayout.h" | |
17 | |
18 CXFA_FFPushButton::CXFA_FFPushButton(CXFA_FFPageView* pPageView, | |
19 CXFA_WidgetAcc* pDataAcc) | |
20 : CXFA_FFField(pPageView, pDataAcc), | |
21 m_pRolloverTextLayout(NULL), | |
22 m_pDownTextLayout(NULL), | |
23 m_pDownProvider(NULL), | |
24 m_pRollProvider(NULL), | |
25 m_pOldDelegate(NULL) {} | |
26 CXFA_FFPushButton::~CXFA_FFPushButton() { | |
27 CXFA_FFPushButton::UnloadWidget(); | |
28 } | |
29 void CXFA_FFPushButton::RenderWidget(CFX_Graphics* pGS, | |
30 CFX_Matrix* pMatrix, | |
31 FX_DWORD dwStatus, | |
32 int32_t iRotate) { | |
33 if (!IsMatchVisibleStatus(dwStatus)) { | |
34 return; | |
35 } | |
36 CFX_Matrix mtRotate; | |
37 GetRotateMatrix(mtRotate); | |
38 if (pMatrix) { | |
39 mtRotate.Concat(*pMatrix); | |
40 } | |
41 CXFA_FFWidget::RenderWidget(pGS, &mtRotate, dwStatus); | |
42 RenderHighlightCaption(pGS, &mtRotate); | |
43 CFX_RectF rtWidget; | |
44 GetRectWithoutRotate(rtWidget); | |
45 CFX_Matrix mt; | |
46 mt.Set(1, 0, 0, 1, rtWidget.left, rtWidget.top); | |
47 mt.Concat(mtRotate); | |
48 GetApp()->GetWidgetMgrDelegate()->OnDrawWidget(m_pNormalWidget->GetWidget(), | |
49 pGS, &mt); | |
50 } | |
51 FX_BOOL CXFA_FFPushButton::LoadWidget() { | |
52 FXSYS_assert(m_pNormalWidget == NULL); | |
53 CFWL_PushButton* pPushButton = CFWL_PushButton::Create(); | |
54 if (pPushButton) { | |
55 pPushButton->Initialize(); | |
56 } | |
57 m_pOldDelegate = pPushButton->SetDelegate(this); | |
58 m_pNormalWidget = (CFWL_Widget*)pPushButton; | |
59 IFWL_Widget* pWidget = m_pNormalWidget->GetWidget(); | |
60 m_pNormalWidget->SetPrivateData(pWidget, this, NULL); | |
61 IFWL_NoteDriver* pNoteDriver = FWL_GetApp()->GetNoteDriver(); | |
62 pNoteDriver->RegisterEventTarget(pWidget, pWidget); | |
63 m_pNormalWidget->LockUpdate(); | |
64 UpdateWidgetProperty(); | |
65 LoadHighlightCaption(); | |
66 m_pNormalWidget->UnlockUpdate(); | |
67 return CXFA_FFField::LoadWidget(); | |
68 } | |
69 void CXFA_FFPushButton::UpdateWidgetProperty() { | |
70 FX_DWORD dwStyleEx = 0; | |
71 switch (m_pDataAcc->GetButtonHighlight()) { | |
72 case XFA_ATTRIBUTEENUM_Inverted: | |
73 dwStyleEx = XFA_FWL_PSBSTYLEEXT_HiliteInverted; | |
74 break; | |
75 case XFA_ATTRIBUTEENUM_Outline: | |
76 dwStyleEx = XFA_FWL_PSBSTYLEEXT_HiliteOutLine; | |
77 break; | |
78 case XFA_ATTRIBUTEENUM_Push: | |
79 dwStyleEx = XFA_FWL_PSBSTYLEEXT_HilitePush; | |
80 break; | |
81 default: | |
82 break; | |
83 } | |
84 m_pNormalWidget->ModifyStylesEx(dwStyleEx, 0xFFFFFFFF); | |
85 } | |
86 void CXFA_FFPushButton::UnloadWidget() { | |
87 if (m_pRolloverTextLayout) { | |
88 delete m_pRolloverTextLayout; | |
89 m_pRolloverTextLayout = NULL; | |
90 } | |
91 if (m_pDownTextLayout) { | |
92 delete m_pDownTextLayout; | |
93 m_pDownTextLayout = NULL; | |
94 } | |
95 if (m_pDownProvider) { | |
96 delete m_pDownProvider; | |
97 m_pDownProvider = NULL; | |
98 } | |
99 if (m_pRollProvider) { | |
100 delete m_pRollProvider; | |
101 m_pRollProvider = NULL; | |
102 } | |
103 CXFA_FFField::UnloadWidget(); | |
104 } | |
105 FX_BOOL CXFA_FFPushButton::PerformLayout() { | |
106 CXFA_FFWidget::PerformLayout(); | |
107 CFX_RectF rtWidget; | |
108 GetRectWithoutRotate(rtWidget); | |
109 m_rtUI = rtWidget; | |
110 if (CXFA_Margin mgWidget = m_pDataAcc->GetMargin()) { | |
111 XFA_RectWidthoutMargin(rtWidget, mgWidget); | |
112 } | |
113 CXFA_Caption caption = m_pDataAcc->GetCaption(); | |
114 m_rtCaption.Set(rtWidget.left, rtWidget.top, rtWidget.width, rtWidget.height); | |
115 if (CXFA_Margin mgCap = caption.GetMargin()) { | |
116 XFA_RectWidthoutMargin(m_rtCaption, mgCap); | |
117 } | |
118 LayoutHighlightCaption(); | |
119 SetFWLRect(); | |
120 if (m_pNormalWidget) { | |
121 m_pNormalWidget->Update(); | |
122 } | |
123 return TRUE; | |
124 } | |
125 FX_FLOAT CXFA_FFPushButton::GetLineWidth() { | |
126 CXFA_Border border = m_pDataAcc->GetBorder(); | |
127 if (border && border.GetPresence() == XFA_ATTRIBUTEENUM_Visible) { | |
128 CXFA_Edge edge = border.GetEdge(0); | |
129 return edge.GetThickness(); | |
130 } | |
131 return 0; | |
132 } | |
133 FX_ARGB CXFA_FFPushButton::GetLineColor() { | |
134 return 0xFF000000; | |
135 } | |
136 FX_ARGB CXFA_FFPushButton::GetFillColor() { | |
137 return 0xFFFFFFFF; | |
138 } | |
139 void CXFA_FFPushButton::LoadHighlightCaption() { | |
140 CXFA_Caption caption = m_pDataAcc->GetCaption(); | |
141 if (caption && caption.GetPresence() != XFA_ATTRIBUTEENUM_Hidden) { | |
142 { | |
143 CFX_WideString wsRollover; | |
144 FX_BOOL bRichText; | |
145 if (m_pDataAcc->GetButtonRollover(wsRollover, bRichText)) { | |
146 if (m_pRollProvider == NULL) { | |
147 m_pRollProvider = | |
148 new CXFA_TextProvider(m_pDataAcc, XFA_TEXTPROVIDERTYPE_Rollover); | |
149 } | |
150 m_pRolloverTextLayout = new CXFA_TextLayout(m_pRollProvider); | |
151 } | |
152 CFX_WideString wsDown; | |
153 if (m_pDataAcc->GetButtonDown(wsDown, bRichText)) { | |
154 if (m_pDownProvider == NULL) { | |
155 m_pDownProvider = | |
156 new CXFA_TextProvider(m_pDataAcc, XFA_TEXTPROVIDERTYPE_Down); | |
157 } | |
158 m_pDownTextLayout = new CXFA_TextLayout(m_pDownProvider); | |
159 } | |
160 } | |
161 } | |
162 } | |
163 void CXFA_FFPushButton::LayoutHighlightCaption() { | |
164 CFX_SizeF sz(m_rtCaption.width, m_rtCaption.height); | |
165 LayoutCaption(); | |
166 if (m_pRolloverTextLayout) { | |
167 m_pRolloverTextLayout->Layout(sz); | |
168 } | |
169 if (m_pDownTextLayout) { | |
170 m_pDownTextLayout->Layout(sz); | |
171 } | |
172 } | |
173 void CXFA_FFPushButton::RenderHighlightCaption(CFX_Graphics* pGS, | |
174 CFX_Matrix* pMatrix) { | |
175 CXFA_TextLayout* pCapTextLayout = m_pDataAcc->GetCaptionTextLayout(); | |
176 CXFA_Caption caption = m_pDataAcc->GetCaption(); | |
177 if (caption && caption.GetPresence() == XFA_ATTRIBUTEENUM_Visible) { | |
178 CFX_RenderDevice* pRenderDevice = pGS->GetRenderDevice(); | |
179 CFX_RectF rtWidget; | |
180 GetRectWithoutRotate(rtWidget); | |
181 CFX_RectF rtClip = m_rtCaption; | |
182 rtClip.Intersect(rtWidget); | |
183 CFX_Matrix mt; | |
184 mt.Set(1, 0, 0, 1, m_rtCaption.left, m_rtCaption.top); | |
185 if (pMatrix) { | |
186 pMatrix->TransformRect(rtClip); | |
187 mt.Concat(*pMatrix); | |
188 } | |
189 { | |
190 FX_DWORD dwState = m_pNormalWidget->GetStates(); | |
191 if (m_pDownTextLayout && (dwState & FWL_STATE_PSB_Pressed) && | |
192 (dwState & FWL_STATE_PSB_Hovered)) { | |
193 if (m_pDownTextLayout->DrawString(pRenderDevice, mt, rtClip)) { | |
194 return; | |
195 } | |
196 } else if (m_pRolloverTextLayout && (dwState & FWL_STATE_PSB_Hovered)) { | |
197 if (m_pRolloverTextLayout->DrawString(pRenderDevice, mt, rtClip)) { | |
198 return; | |
199 } | |
200 } | |
201 } | |
202 if (pCapTextLayout) { | |
203 pCapTextLayout->DrawString(pRenderDevice, mt, rtClip); | |
204 } | |
205 } | |
206 } | |
207 int32_t CXFA_FFPushButton::OnProcessMessage(CFWL_Message* pMessage) { | |
208 return m_pOldDelegate->OnProcessMessage(pMessage); | |
209 } | |
210 FWL_ERR CXFA_FFPushButton::OnProcessEvent(CFWL_Event* pEvent) { | |
211 m_pOldDelegate->OnProcessEvent(pEvent); | |
212 return CXFA_FFField::OnProcessEvent(pEvent); | |
213 } | |
214 FWL_ERR CXFA_FFPushButton::OnDrawWidget(CFX_Graphics* pGraphics, | |
215 const CFX_Matrix* pMatrix) { | |
216 if (m_pNormalWidget->GetStylesEx() & XFA_FWL_PSBSTYLEEXT_HiliteInverted) { | |
217 if ((m_pNormalWidget->GetStates() & FWL_STATE_PSB_Pressed) && | |
218 (m_pNormalWidget->GetStates() & FWL_STATE_PSB_Hovered)) { | |
219 CFX_RectF rtFill; | |
220 m_pNormalWidget->GetWidgetRect(rtFill); | |
221 rtFill.left = rtFill.top = 0; | |
222 FX_FLOAT fLineWith = GetLineWidth(); | |
223 rtFill.Deflate(fLineWith, fLineWith); | |
224 CFX_Color cr(FXARGB_MAKE(128, 128, 255, 255)); | |
225 pGraphics->SetFillColor(&cr); | |
226 CFX_Path path; | |
227 path.Create(); | |
228 path.AddRectangle(rtFill.left, rtFill.top, rtFill.width, rtFill.height); | |
229 pGraphics->FillPath(&path, FXFILL_WINDING, (CFX_Matrix*)pMatrix); | |
230 } | |
231 } else if (m_pNormalWidget->GetStylesEx() & | |
232 XFA_FWL_PSBSTYLEEXT_HiliteOutLine) { | |
233 if ((m_pNormalWidget->GetStates() & FWL_STATE_PSB_Pressed) && | |
234 (m_pNormalWidget->GetStates() & FWL_STATE_PSB_Hovered)) { | |
235 FX_FLOAT fLineWidth = GetLineWidth(); | |
236 CFX_Color cr(FXARGB_MAKE(255, 128, 255, 255)); | |
237 pGraphics->SetStrokeColor(&cr); | |
238 pGraphics->SetLineWidth(fLineWidth); | |
239 CFX_Path path; | |
240 path.Create(); | |
241 CFX_RectF rect; | |
242 m_pNormalWidget->GetWidgetRect(rect); | |
243 path.AddRectangle(0, 0, rect.width, rect.height); | |
244 pGraphics->StrokePath(&path, (CFX_Matrix*)pMatrix); | |
245 } | |
246 } else if (m_pNormalWidget->GetStylesEx() & XFA_FWL_PSBSTYLEEXT_HilitePush) { | |
247 } | |
248 return FWL_ERR_Succeeded; | |
249 } | |
OLD | NEW |