Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cfwl_pushbutton.cpp
Go to the documentation of this file.
1// Copyright 2014 The PDFium Authors
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/fwl/cfwl_pushbutton.h"
8
9#include "xfa/fde/cfde_textout.h"
10#include "xfa/fwl/cfwl_event.h"
11#include "xfa/fwl/cfwl_eventmouse.h"
12#include "xfa/fwl/cfwl_messagekey.h"
13#include "xfa/fwl/cfwl_messagemouse.h"
14#include "xfa/fwl/cfwl_notedriver.h"
15#include "xfa/fwl/cfwl_themebackground.h"
16#include "xfa/fwl/cfwl_themetext.h"
17#include "xfa/fwl/fwl_widgetdef.h"
18#include "xfa/fwl/ifwl_themeprovider.h"
19
20namespace pdfium {
21
22CFWL_PushButton::CFWL_PushButton(CFWL_App* app)
23 : CFWL_Widget(app, Properties(), nullptr) {}
24
25CFWL_PushButton::~CFWL_PushButton() = default;
26
27FWL_Type CFWL_PushButton::GetClassID() const {
29}
30
31void CFWL_PushButton::SetStates(uint32_t dwStates) {
32 if (dwStates & FWL_STATE_WGT_Disabled) {
34 return;
35 }
36 CFWL_Widget::SetStates(dwStates);
37}
38
39void CFWL_PushButton::Update() {
40 if (IsLocked())
41 return;
42
43 m_ClientRect = GetClientRect();
44 m_CaptionRect = m_ClientRect;
45}
46
47void CFWL_PushButton::DrawWidget(CFGAS_GEGraphics* pGraphics,
48 const CFX_Matrix& matrix) {
49 if (!pGraphics)
50 return;
51
52 if (HasBorder())
53 DrawBorder(pGraphics, CFWL_ThemePart::Part::kBorder, matrix);
54
55 DrawBkground(pGraphics, matrix);
56}
57
58void CFWL_PushButton::DrawBkground(CFGAS_GEGraphics* pGraphics,
59 const CFX_Matrix& matrix) {
60 CFWL_ThemeBackground param(CFWL_ThemePart::Part::kBackground, this,
61 pGraphics);
62 param.m_dwStates = GetPartStates();
63 param.m_matrix = matrix;
64 param.m_PartRect = m_ClientRect;
66 param.m_pRtData = &m_CaptionRect;
67 GetThemeProvider()->DrawBackground(param);
68}
69
70Mask<CFWL_PartState> CFWL_PushButton::GetPartStates() {
71 Mask<CFWL_PartState> dwStates = CFWL_PartState::kNormal;
73 dwStates |= CFWL_PartState::kFocused;
77 dwStates |= CFWL_PartState::kPressed;
79 dwStates |= CFWL_PartState::kHovered;
80 return dwStates;
81}
82
83void CFWL_PushButton::OnProcessMessage(CFWL_Message* pMessage) {
84 if (!IsEnabled())
85 return;
86
87 switch (pMessage->GetType()) {
89 OnFocusGained();
90 break;
92 OnFocusLost();
93 break;
95 CFWL_MessageMouse* pMsg = static_cast<CFWL_MessageMouse*>(pMessage);
96 switch (pMsg->m_dwCmd) {
97 case CFWL_MessageMouse::MouseCommand::kLeftButtonDown:
98 OnLButtonDown(pMsg);
99 break;
100 case CFWL_MessageMouse::MouseCommand::kLeftButtonUp:
101 OnLButtonUp(pMsg);
102 break;
103 case CFWL_MessageMouse::MouseCommand::kMove:
104 OnMouseMove(pMsg);
105 break;
106 case CFWL_MessageMouse::MouseCommand::kLeave:
107 OnMouseLeave(pMsg);
108 break;
109 default:
110 break;
111 }
112 break;
113 }
115 CFWL_MessageKey* pKey = static_cast<CFWL_MessageKey*>(pMessage);
116 if (pKey->m_dwCmd == CFWL_MessageKey::KeyCommand::kKeyDown)
117 OnKeyDown(pKey);
118 break;
119 }
120 default:
121 break;
122 }
123 // Dst target could be |this|, continue only if not destroyed by above.
124 if (pMessage->GetDstTarget())
126}
127
128void CFWL_PushButton::OnDrawWidget(CFGAS_GEGraphics* pGraphics,
129 const CFX_Matrix& matrix) {
130 DrawWidget(pGraphics, matrix);
131}
132
133void CFWL_PushButton::OnFocusGained() {
135 RepaintRect(m_ClientRect);
136}
137
138void CFWL_PushButton::OnFocusLost() {
140 RepaintRect(m_ClientRect);
141}
142
143void CFWL_PushButton::OnLButtonDown(CFWL_MessageMouse* pMsg) {
144 m_bBtnDown = true;
147 RepaintRect(m_ClientRect);
148}
149
150void CFWL_PushButton::OnLButtonUp(CFWL_MessageMouse* pMsg) {
151 m_bBtnDown = false;
152 if (m_ClientRect.Contains(pMsg->m_pos)) {
155 } else {
158 }
159 if (m_ClientRect.Contains(pMsg->m_pos)) {
160 CFWL_Event wmClick(CFWL_Event::Type::Click, this);
161 DispatchEvent(&wmClick);
162 }
163 RepaintRect(m_ClientRect);
164}
165
166void CFWL_PushButton::OnMouseMove(CFWL_MessageMouse* pMsg) {
167 bool bRepaint = false;
168 if (m_bBtnDown) {
169 if (m_ClientRect.Contains(pMsg->m_pos)) {
172 bRepaint = true;
173 }
176 bRepaint = true;
177 }
178 } else {
181 bRepaint = true;
182 }
185 bRepaint = true;
186 }
187 }
188 } else {
189 if (!m_ClientRect.Contains(pMsg->m_pos))
190 return;
193 bRepaint = true;
194 }
195 }
196 if (bRepaint)
197 RepaintRect(m_ClientRect);
198}
199
200void CFWL_PushButton::OnMouseLeave(CFWL_MessageMouse* pMsg) {
201 m_bBtnDown = false;
204 RepaintRect(m_ClientRect);
205}
206
207void CFWL_PushButton::OnKeyDown(CFWL_MessageKey* pMsg) {
209 return;
210
211 CFWL_EventMouse wmMouse(this, nullptr,
212 CFWL_MessageMouse::MouseCommand::kLeftButtonUp);
213 DispatchEvent(&wmMouse);
214 if (!wmMouse.GetSrcTarget())
215 return;
216
217 CFWL_Event wmClick(CFWL_Event::Type::Click, this);
218 DispatchEvent(&wmClick);
219}
220
221} // namespace pdfium
#define FWL_STATE_PSB_Pressed
#define FWL_STATE_PSB_Hovered
#define FWL_STATE_WGT_Focused
Definition cfwl_widget.h:44
#define FWL_STATE_WGT_Disabled
Definition cfwl_widget.h:43
CFX_Matrix & operator=(const CFX_Matrix &other)=default
CFX_RectF & operator=(const CFX_RectF &other)=default
CFWL_Widget * GetSrcTarget() const
Definition cfwl_event.h:42
const uint32_t m_dwKeyCodeOrChar
const KeyCommand m_dwCmd
Type GetType() const
CFWL_Widget * GetDstTarget() const
void DrawWidget(CFGAS_GEGraphics *pGraphics, const CFX_Matrix &matrix) override
void SetStates(uint32_t dwStates) override
void OnDrawWidget(CFGAS_GEGraphics *pGraphics, const CFX_Matrix &matrix) override
FWL_Type GetClassID() const override
void OnProcessMessage(CFWL_Message *pMessage) override
void OnProcessMessage(CFWL_Message *pMessage) override
void RepaintRect(const CFX_RectF &pRect)
bool HasBorder() const
void DispatchEvent(CFWL_Event *pEvent)
CFWL_Widget(CFWL_App *app, const Properties &properties, CFWL_Widget *pOuter)
void DrawBorder(CFGAS_GEGraphics *pGraphics, CFWL_ThemePart::Part iPartBorder, const CFX_Matrix &pMatrix)
virtual CFX_RectF GetClientRect()
IFWL_ThemeProvider * GetThemeProvider() const
bool IsLocked() const
Properties m_Properties
bool IsEnabled() const
virtual void SetStates(uint32_t dwStates)
@ XFA_FWL_VKEY_Return