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_caret.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_caret.h"
8
9#include <utility>
10
11#include "xfa/fwl/cfwl_app.h"
12#include "xfa/fwl/cfwl_notedriver.h"
13#include "xfa/fwl/cfwl_themebackground.h"
14#include "xfa/fwl/ifwl_themeprovider.h"
15
16namespace pdfium {
17
18namespace {
19
20const uint32_t kBlinkPeriodMs = 600;
21
22constexpr int kStateHighlight = (1 << 0);
23
24} // namespace
25
26CFWL_Caret::CFWL_Caret(CFWL_App* app,
27 const Properties& properties,
28 CFWL_Widget* pOuter)
29 : CFWL_Widget(app, properties, pOuter) {
30 SetStates(kStateHighlight);
31}
32
33CFWL_Caret::~CFWL_Caret() = default;
34
35FWL_Type CFWL_Caret::GetClassID() const {
36 return FWL_Type::Caret;
37}
38
39void CFWL_Caret::Update() {}
40
41void CFWL_Caret::DrawWidget(CFGAS_GEGraphics* pGraphics,
42 const CFX_Matrix& matrix) {
43 if (!pGraphics)
44 return;
45
46 DrawCaretBK(pGraphics, matrix);
47}
48
49void CFWL_Caret::ShowCaret() {
50 m_pTimer = std::make_unique<CFX_Timer>(GetFWLApp()->GetTimerHandler(), this,
51 kBlinkPeriodMs);
53 SetStates(kStateHighlight);
54}
55
56void CFWL_Caret::HideCaret() {
57 m_pTimer.reset();
59}
60
61void CFWL_Caret::DrawCaretBK(CFGAS_GEGraphics* pGraphics,
62 const CFX_Matrix& mtMatrix) {
63 if (!(m_Properties.m_dwStates & kStateHighlight))
64 return;
65
66 CFWL_ThemeBackground param(CFWL_ThemePart::Part::kBackground, this,
67 pGraphics);
68 param.m_PartRect = CFX_RectF(0, 0, GetWidgetRect().Size());
69 param.m_dwStates = CFWL_PartState::kHightLight;
70 param.m_matrix = mtMatrix;
71 GetThemeProvider()->DrawBackground(param);
72}
73
74void CFWL_Caret::OnProcessMessage(CFWL_Message* pMessage) {}
75
76void CFWL_Caret::OnDrawWidget(CFGAS_GEGraphics* pGraphics,
77 const CFX_Matrix& matrix) {
78 DrawWidget(pGraphics, matrix);
79}
80
81void CFWL_Caret::OnTimerFired() {
82 if (!(GetStates() & kStateHighlight))
83 SetStates(kStateHighlight);
84 else
85 RemoveStates(kStateHighlight);
86
89}
90
91} // namespace pdfium
#define FWL_STATE_WGT_Invisible
Definition cfwl_widget.h:45
CFX_Matrix & operator=(const CFX_Matrix &other)=default
CFX_RectF & operator=(const CFX_RectF &other)=default
constexpr CFX_RectF(float dst_left, float dst_top, float dst_width, float dst_height)
void OnDrawWidget(CFGAS_GEGraphics *pGraphics, const CFX_Matrix &matrix) override
FWL_Type GetClassID() const override
void OnProcessMessage(CFWL_Message *pMessage) override
void DrawWidget(CFGAS_GEGraphics *pGraphics, const CFX_Matrix &matrix) override
~CFWL_Caret() override
void OnTimerFired() override
void Update() override
virtual CFX_RectF GetWidgetRect()
void RepaintRect(const CFX_RectF &pRect)
virtual void RemoveStates(uint32_t dwStates)
CFWL_Widget(CFWL_App *app, const Properties &properties, CFWL_Widget *pOuter)
uint32_t GetStates() const
IFWL_ThemeProvider * GetThemeProvider() const
Properties m_Properties
virtual void SetStates(uint32_t dwStates)