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/core/ifwl_pushbutton.h" | 7 #include "xfa/fwl/core/ifwl_pushbutton.h" |
8 | 8 |
9 #include "third_party/base/ptr_util.h" | 9 #include "third_party/base/ptr_util.h" |
10 #include "xfa/fde/tto/fde_textout.h" | 10 #include "xfa/fde/tto/fde_textout.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 m_rtCaption.Set(0, 0, 0, 0); | 26 m_rtCaption.Set(0, 0, 0, 0); |
27 } | 27 } |
28 | 28 |
29 IFWL_PushButton::~IFWL_PushButton() {} | 29 IFWL_PushButton::~IFWL_PushButton() {} |
30 | 30 |
31 FWL_Type IFWL_PushButton::GetClassID() const { | 31 FWL_Type IFWL_PushButton::GetClassID() const { |
32 return FWL_Type::PushButton; | 32 return FWL_Type::PushButton; |
33 } | 33 } |
34 | 34 |
35 void IFWL_PushButton::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) { | 35 void IFWL_PushButton::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) { |
36 if (bAutoSize) { | 36 if (!bAutoSize) { |
37 rect.Set(0, 0, 0, 0); | |
38 if (!m_pProperties->m_pThemeProvider) { | |
39 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | |
40 } | |
41 CFX_WideString wsCaption; | |
42 IFWL_PushButtonDP* pData = | |
43 static_cast<IFWL_PushButtonDP*>(m_pProperties->m_pDataProvider); | |
44 if (pData) { | |
45 pData->GetCaption(this, wsCaption); | |
46 } | |
47 int32_t iLen = wsCaption.GetLength(); | |
48 if (iLen > 0) { | |
49 CFX_SizeF sz = CalcTextSize(wsCaption, m_pProperties->m_pThemeProvider); | |
50 rect.Set(0, 0, sz.x, sz.y); | |
51 } | |
52 FX_FLOAT* fcaption = | |
53 static_cast<FX_FLOAT*>(GetThemeCapacity(CFWL_WidgetCapacity::Margin)); | |
54 rect.Inflate(*fcaption, *fcaption); | |
55 IFWL_Widget::GetWidgetRect(rect, true); | |
56 } else { | |
57 rect = m_pProperties->m_rtWidget; | 37 rect = m_pProperties->m_rtWidget; |
| 38 return; |
58 } | 39 } |
| 40 |
| 41 rect.Set(0, 0, 0, 0); |
| 42 if (!m_pProperties->m_pThemeProvider) |
| 43 m_pProperties->m_pThemeProvider = GetAvailableTheme(); |
| 44 |
| 45 CFX_WideString wsCaption; |
| 46 IFWL_PushButtonDP* pData = |
| 47 static_cast<IFWL_PushButtonDP*>(m_pProperties->m_pDataProvider); |
| 48 if (pData) |
| 49 pData->GetCaption(this, wsCaption); |
| 50 |
| 51 int32_t iLen = wsCaption.GetLength(); |
| 52 if (iLen > 0) { |
| 53 CFX_SizeF sz = CalcTextSize(wsCaption, m_pProperties->m_pThemeProvider); |
| 54 rect.Set(0, 0, sz.x, sz.y); |
| 55 } |
| 56 |
| 57 FX_FLOAT* fcaption = |
| 58 static_cast<FX_FLOAT*>(GetThemeCapacity(CFWL_WidgetCapacity::Margin)); |
| 59 rect.Inflate(*fcaption, *fcaption); |
| 60 IFWL_Widget::GetWidgetRect(rect, true); |
59 } | 61 } |
60 | 62 |
61 void IFWL_PushButton::SetStates(uint32_t dwStates, bool bSet) { | 63 void IFWL_PushButton::SetStates(uint32_t dwStates, bool bSet) { |
62 if ((dwStates & FWL_WGTSTATE_Disabled) && bSet) { | 64 if ((dwStates & FWL_WGTSTATE_Disabled) && bSet) { |
63 m_pProperties->m_dwStates = FWL_WGTSTATE_Disabled; | 65 m_pProperties->m_dwStates = FWL_WGTSTATE_Disabled; |
64 return; | 66 return; |
65 } | 67 } |
66 IFWL_Widget::SetStates(dwStates, bSet); | 68 IFWL_Widget::SetStates(dwStates, bSet); |
67 } | 69 } |
68 | 70 |
69 void IFWL_PushButton::Update() { | 71 void IFWL_PushButton::Update() { |
70 if (IsLocked()) { | 72 if (IsLocked()) |
71 return; | 73 return; |
72 } | 74 if (!m_pProperties->m_pThemeProvider) |
73 if (!m_pProperties->m_pThemeProvider) { | |
74 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | 75 m_pProperties->m_pThemeProvider = GetAvailableTheme(); |
75 } | 76 |
76 UpdateTextOutStyles(); | 77 UpdateTextOutStyles(); |
77 GetClientRect(m_rtClient); | 78 GetClientRect(m_rtClient); |
78 m_rtCaption = m_rtClient; | 79 m_rtCaption = m_rtClient; |
79 FX_FLOAT* fcaption = | 80 FX_FLOAT* fcaption = |
80 static_cast<FX_FLOAT*>(GetThemeCapacity(CFWL_WidgetCapacity::Margin)); | 81 static_cast<FX_FLOAT*>(GetThemeCapacity(CFWL_WidgetCapacity::Margin)); |
81 m_rtCaption.Inflate(-*fcaption, -*fcaption); | 82 m_rtCaption.Inflate(-*fcaption, -*fcaption); |
82 } | 83 } |
83 | 84 |
84 void IFWL_PushButton::DrawWidget(CFX_Graphics* pGraphics, | 85 void IFWL_PushButton::DrawWidget(CFX_Graphics* pGraphics, |
85 const CFX_Matrix* pMatrix) { | 86 const CFX_Matrix* pMatrix) { |
86 if (!pGraphics) | 87 if (!pGraphics) |
87 return; | 88 return; |
88 if (!m_pProperties->m_pThemeProvider) | 89 if (!m_pProperties->m_pThemeProvider) |
89 return; | 90 return; |
| 91 |
90 IFWL_PushButtonDP* pData = | 92 IFWL_PushButtonDP* pData = |
91 static_cast<IFWL_PushButtonDP*>(m_pProperties->m_pDataProvider); | 93 static_cast<IFWL_PushButtonDP*>(m_pProperties->m_pDataProvider); |
92 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; | 94 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; |
93 if (HasBorder()) { | 95 if (HasBorder()) { |
94 DrawBorder(pGraphics, CFWL_Part::Border, m_pProperties->m_pThemeProvider, | 96 DrawBorder(pGraphics, CFWL_Part::Border, m_pProperties->m_pThemeProvider, |
95 pMatrix); | 97 pMatrix); |
96 } | 98 } |
97 if (HasEdge()) { | 99 if (HasEdge()) { |
98 DrawEdge(pGraphics, CFWL_Part::Edge, m_pProperties->m_pThemeProvider, | 100 DrawEdge(pGraphics, CFWL_Part::Edge, m_pProperties->m_pThemeProvider, |
99 pMatrix); | 101 pMatrix); |
100 } | 102 } |
101 DrawBkground(pGraphics, m_pProperties->m_pThemeProvider, pMatrix); | 103 DrawBkground(pGraphics, m_pProperties->m_pThemeProvider, pMatrix); |
102 CFX_Matrix matrix; | 104 CFX_Matrix matrix; |
103 matrix.Concat(*pMatrix); | 105 matrix.Concat(*pMatrix); |
104 | 106 |
105 CFX_WideString wsCaption; | 107 CFX_WideString wsCaption; |
106 if (pData) { | 108 if (pData) |
107 pData->GetCaption(this, wsCaption); | 109 pData->GetCaption(this, wsCaption); |
108 } | 110 |
109 CFX_RectF rtText; | 111 CFX_RectF rtText; |
110 rtText.Set(0, 0, 0, 0); | 112 rtText.Set(0, 0, 0, 0); |
111 if (!wsCaption.IsEmpty()) | 113 if (!wsCaption.IsEmpty()) |
112 CalcTextRect(wsCaption, pTheme, 0, m_iTTOAlign, rtText); | 114 CalcTextRect(wsCaption, pTheme, 0, m_iTTOAlign, rtText); |
113 | 115 |
114 switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_PSB_ModeMask) { | 116 switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_PSB_ModeMask) { |
115 case FWL_STYLEEXT_PSB_TextOnly: | 117 case FWL_STYLEEXT_PSB_TextOnly: |
116 DrawText(pGraphics, m_pProperties->m_pThemeProvider, &matrix); | 118 DrawText(pGraphics, m_pProperties->m_pThemeProvider, &matrix); |
117 break; | 119 break; |
118 case FWL_STYLEEXT_PSB_IconOnly: | 120 case FWL_STYLEEXT_PSB_IconOnly: |
119 case FWL_STYLEEXT_PSB_TextIcon: | 121 case FWL_STYLEEXT_PSB_TextIcon: |
120 break; | 122 break; |
121 } | 123 } |
122 } | 124 } |
123 | 125 |
124 void IFWL_PushButton::DrawBkground(CFX_Graphics* pGraphics, | 126 void IFWL_PushButton::DrawBkground(CFX_Graphics* pGraphics, |
125 IFWL_ThemeProvider* pTheme, | 127 IFWL_ThemeProvider* pTheme, |
126 const CFX_Matrix* pMatrix) { | 128 const CFX_Matrix* pMatrix) { |
127 CFWL_ThemeBackground param; | 129 CFWL_ThemeBackground param; |
128 param.m_pWidget = this; | 130 param.m_pWidget = this; |
129 param.m_iPart = CFWL_Part::Background; | 131 param.m_iPart = CFWL_Part::Background; |
130 param.m_dwStates = GetPartStates(); | 132 param.m_dwStates = GetPartStates(); |
131 param.m_pGraphics = pGraphics; | 133 param.m_pGraphics = pGraphics; |
132 if (pMatrix) { | 134 if (pMatrix) |
133 param.m_matrix.Concat(*pMatrix); | 135 param.m_matrix.Concat(*pMatrix); |
134 } | |
135 param.m_rtPart = m_rtClient; | 136 param.m_rtPart = m_rtClient; |
136 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) { | 137 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) |
137 param.m_pData = &m_rtCaption; | 138 param.m_pData = &m_rtCaption; |
138 } | |
139 pTheme->DrawBackground(¶m); | 139 pTheme->DrawBackground(¶m); |
140 } | 140 } |
141 | 141 |
142 void IFWL_PushButton::DrawText(CFX_Graphics* pGraphics, | 142 void IFWL_PushButton::DrawText(CFX_Graphics* pGraphics, |
143 IFWL_ThemeProvider* pTheme, | 143 IFWL_ThemeProvider* pTheme, |
144 const CFX_Matrix* pMatrix) { | 144 const CFX_Matrix* pMatrix) { |
145 if (!m_pProperties->m_pDataProvider) | 145 if (!m_pProperties->m_pDataProvider) |
146 return; | 146 return; |
| 147 |
147 CFX_WideString wsCaption; | 148 CFX_WideString wsCaption; |
148 m_pProperties->m_pDataProvider->GetCaption(this, wsCaption); | 149 m_pProperties->m_pDataProvider->GetCaption(this, wsCaption); |
149 if (wsCaption.IsEmpty()) { | 150 if (wsCaption.IsEmpty()) |
150 return; | 151 return; |
151 } | 152 |
152 CFWL_ThemeText param; | 153 CFWL_ThemeText param; |
153 param.m_pWidget = this; | 154 param.m_pWidget = this; |
154 param.m_iPart = CFWL_Part::Caption; | 155 param.m_iPart = CFWL_Part::Caption; |
155 param.m_dwStates = GetPartStates(); | 156 param.m_dwStates = GetPartStates(); |
156 param.m_pGraphics = pGraphics; | 157 param.m_pGraphics = pGraphics; |
157 if (pMatrix) { | 158 if (pMatrix) |
158 param.m_matrix.Concat(*pMatrix); | 159 param.m_matrix.Concat(*pMatrix); |
159 } | |
160 param.m_rtPart = m_rtCaption; | 160 param.m_rtPart = m_rtCaption; |
161 param.m_wsText = wsCaption; | 161 param.m_wsText = wsCaption; |
162 param.m_dwTTOStyles = m_dwTTOStyles; | 162 param.m_dwTTOStyles = m_dwTTOStyles; |
163 param.m_iTTOAlign = m_iTTOAlign; | 163 param.m_iTTOAlign = m_iTTOAlign; |
164 pTheme->DrawText(¶m); | 164 pTheme->DrawText(¶m); |
165 } | 165 } |
166 | 166 |
167 uint32_t IFWL_PushButton::GetPartStates() { | 167 uint32_t IFWL_PushButton::GetPartStates() { |
168 uint32_t dwStates = CFWL_PartState_Normal; | 168 uint32_t dwStates = CFWL_PartState_Normal; |
169 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) { | 169 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) |
170 dwStates |= CFWL_PartState_Focused; | 170 dwStates |= CFWL_PartState_Focused; |
171 } | 171 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) |
172 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) { | |
173 dwStates = CFWL_PartState_Disabled; | 172 dwStates = CFWL_PartState_Disabled; |
174 } else if (m_pProperties->m_dwStates & FWL_STATE_PSB_Pressed) { | 173 else if (m_pProperties->m_dwStates & FWL_STATE_PSB_Pressed) |
175 dwStates |= CFWL_PartState_Pressed; | 174 dwStates |= CFWL_PartState_Pressed; |
176 } else if (m_pProperties->m_dwStates & FWL_STATE_PSB_Hovered) { | 175 else if (m_pProperties->m_dwStates & FWL_STATE_PSB_Hovered) |
177 dwStates |= CFWL_PartState_Hovered; | 176 dwStates |= CFWL_PartState_Hovered; |
178 } else if (m_pProperties->m_dwStates & FWL_STATE_PSB_Default) { | 177 else if (m_pProperties->m_dwStates & FWL_STATE_PSB_Default) |
179 dwStates |= CFWL_PartState_Default; | 178 dwStates |= CFWL_PartState_Default; |
180 } | |
181 return dwStates; | 179 return dwStates; |
182 } | 180 } |
183 | 181 |
184 void IFWL_PushButton::UpdateTextOutStyles() { | 182 void IFWL_PushButton::UpdateTextOutStyles() { |
185 m_iTTOAlign = FDE_TTOALIGNMENT_Center; | |
186 switch (m_pProperties->m_dwStyleExes & | 183 switch (m_pProperties->m_dwStyleExes & |
187 (FWL_STYLEEXT_PSB_HLayoutMask | FWL_STYLEEXT_PSB_VLayoutMask)) { | 184 (FWL_STYLEEXT_PSB_HLayoutMask | FWL_STYLEEXT_PSB_VLayoutMask)) { |
188 case FWL_STYLEEXT_PSB_Left | FWL_STYLEEXT_PSB_Top: { | 185 case FWL_STYLEEXT_PSB_Left | FWL_STYLEEXT_PSB_Top: { |
189 m_iTTOAlign = FDE_TTOALIGNMENT_TopLeft; | 186 m_iTTOAlign = FDE_TTOALIGNMENT_TopLeft; |
190 break; | 187 break; |
191 } | 188 } |
192 case FWL_STYLEEXT_PSB_Center | FWL_STYLEEXT_PSB_Top: { | 189 case FWL_STYLEEXT_PSB_Center | FWL_STYLEEXT_PSB_Top: { |
193 m_iTTOAlign = FDE_TTOALIGNMENT_TopCenter; | 190 m_iTTOAlign = FDE_TTOALIGNMENT_TopCenter; |
194 break; | 191 break; |
195 } | 192 } |
196 case FWL_STYLEEXT_PSB_Right | FWL_STYLEEXT_PSB_Top: { | 193 case FWL_STYLEEXT_PSB_Right | FWL_STYLEEXT_PSB_Top: { |
197 m_iTTOAlign = FDE_TTOALIGNMENT_TopRight; | 194 m_iTTOAlign = FDE_TTOALIGNMENT_TopRight; |
198 break; | 195 break; |
199 } | 196 } |
200 case FWL_STYLEEXT_PSB_Left | FWL_STYLEEXT_PSB_VCenter: { | 197 case FWL_STYLEEXT_PSB_Left | FWL_STYLEEXT_PSB_VCenter: { |
201 m_iTTOAlign = FDE_TTOALIGNMENT_CenterLeft; | 198 m_iTTOAlign = FDE_TTOALIGNMENT_CenterLeft; |
202 break; | 199 break; |
203 } | 200 } |
204 case FWL_STYLEEXT_PSB_Center | FWL_STYLEEXT_PSB_VCenter: { | |
205 m_iTTOAlign = FDE_TTOALIGNMENT_Center; | |
206 break; | |
207 } | |
208 case FWL_STYLEEXT_PSB_Right | FWL_STYLEEXT_PSB_VCenter: { | 201 case FWL_STYLEEXT_PSB_Right | FWL_STYLEEXT_PSB_VCenter: { |
209 m_iTTOAlign = FDE_TTOALIGNMENT_CenterRight; | 202 m_iTTOAlign = FDE_TTOALIGNMENT_CenterRight; |
210 break; | 203 break; |
211 } | 204 } |
212 case FWL_STYLEEXT_PSB_Left | FWL_STYLEEXT_PSB_Bottom: { | 205 case FWL_STYLEEXT_PSB_Left | FWL_STYLEEXT_PSB_Bottom: { |
213 m_iTTOAlign = FDE_TTOALIGNMENT_BottomLeft; | 206 m_iTTOAlign = FDE_TTOALIGNMENT_BottomLeft; |
214 break; | 207 break; |
215 } | 208 } |
216 case FWL_STYLEEXT_PSB_Center | FWL_STYLEEXT_PSB_Bottom: { | 209 case FWL_STYLEEXT_PSB_Center | FWL_STYLEEXT_PSB_Bottom: { |
217 m_iTTOAlign = FDE_TTOALIGNMENT_BottomCenter; | 210 m_iTTOAlign = FDE_TTOALIGNMENT_BottomCenter; |
218 break; | 211 break; |
219 } | 212 } |
220 case FWL_STYLEEXT_PSB_Right | FWL_STYLEEXT_PSB_Bottom: { | 213 case FWL_STYLEEXT_PSB_Right | FWL_STYLEEXT_PSB_Bottom: { |
221 m_iTTOAlign = FDE_TTOALIGNMENT_BottomRight; | 214 m_iTTOAlign = FDE_TTOALIGNMENT_BottomRight; |
222 break; | 215 break; |
223 } | 216 } |
224 default: | 217 case FWL_STYLEEXT_PSB_Center | FWL_STYLEEXT_PSB_VCenter: |
| 218 default: { |
| 219 m_iTTOAlign = FDE_TTOALIGNMENT_Center; |
225 break; | 220 break; |
| 221 } |
226 } | 222 } |
227 m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; | 223 m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; |
228 if (m_pProperties->m_dwStyleExes & FWL_WGTSTYLE_RTLReading) { | 224 if (m_pProperties->m_dwStyleExes & FWL_WGTSTYLE_RTLReading) |
229 m_dwTTOStyles |= FDE_TTOSTYLE_RTL; | 225 m_dwTTOStyles |= FDE_TTOSTYLE_RTL; |
230 } | |
231 } | 226 } |
232 | 227 |
233 void IFWL_PushButton::OnProcessMessage(CFWL_Message* pMessage) { | 228 void IFWL_PushButton::OnProcessMessage(CFWL_Message* pMessage) { |
234 if (!pMessage) | 229 if (!pMessage) |
235 return; | 230 return; |
236 if (!IsEnabled()) | 231 if (!IsEnabled()) |
237 return; | 232 return; |
238 | 233 |
239 CFWL_MessageType dwMsgCode = pMessage->GetClassID(); | 234 CFWL_MessageType dwMsgCode = pMessage->GetClassID(); |
240 switch (dwMsgCode) { | 235 switch (dwMsgCode) { |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 CFWL_EvtClick wmClick; | 362 CFWL_EvtClick wmClick; |
368 wmClick.m_pSrcTarget = this; | 363 wmClick.m_pSrcTarget = this; |
369 DispatchEvent(&wmClick); | 364 DispatchEvent(&wmClick); |
370 return; | 365 return; |
371 } | 366 } |
372 if (pMsg->m_dwKeyCode != FWL_VKEY_Tab) | 367 if (pMsg->m_dwKeyCode != FWL_VKEY_Tab) |
373 return; | 368 return; |
374 | 369 |
375 DispatchKeyEvent(pMsg); | 370 DispatchKeyEvent(pMsg); |
376 } | 371 } |
OLD | NEW |