summaryrefslogtreecommitdiff
path: root/fpdfsdk/cpdfsdk_annot.cpp
blob: 9f8cf253faff71d08ea97e488a515a40b30c7d0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Copyright 2016 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#include "fpdfsdk/include/cpdfsdk_annot.h"

#include <algorithm>

#include "fpdfsdk/include/fsdk_mgr.h"
#include "third_party/base/stl_util.h"

#ifdef PDF_ENABLE_XFA
#include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h"
#endif  // PDF_ENABLE_XFA

namespace {

const float kMinWidth = 1.0f;
const float kMinHeight = 1.0f;

}  // namespace

CPDFSDK_Annot::Observer::Observer(CPDFSDK_Annot** pWatchedPtr)
    : m_pWatchedPtr(pWatchedPtr) {
  (*m_pWatchedPtr)->AddObserver(this);
}

CPDFSDK_Annot::Observer::~Observer() {
  if (m_pWatchedPtr)
    (*m_pWatchedPtr)->RemoveObserver(this);
}

void CPDFSDK_Annot::Observer::OnAnnotDestroyed() {
  ASSERT(m_pWatchedPtr);
  *m_pWatchedPtr = nullptr;
  m_pWatchedPtr = nullptr;
}

CPDFSDK_Annot::CPDFSDK_Annot(CPDFSDK_PageView* pPageView)
    : m_pPageView(pPageView), m_bSelected(FALSE) {}

CPDFSDK_Annot::~CPDFSDK_Annot() {
  for (auto* pObserver : m_Observers)
    pObserver->OnAnnotDestroyed();
}

void CPDFSDK_Annot::AddObserver(Observer* pObserver) {
  ASSERT(!pdfium::ContainsKey(m_Observers, pObserver));
  m_Observers.insert(pObserver);
}

void CPDFSDK_Annot::RemoveObserver(Observer* pObserver) {
  ASSERT(pdfium::ContainsKey(m_Observers, pObserver));
  m_Observers.erase(pObserver);
}

#ifdef PDF_ENABLE_XFA

FX_BOOL CPDFSDK_Annot::IsXFAField() {
  return FALSE;
}

CXFA_FFWidget* CPDFSDK_Annot::GetXFAWidget() const {
  return nullptr;
}

CPDFXFA_Page* CPDFSDK_Annot::GetPDFXFAPage() {
  return m_pPageView ? m_pPageView->GetPDFXFAPage() : nullptr;
}

#endif  // PDF_ENABLE_XFA

FX_FLOAT CPDFSDK_Annot::GetMinWidth() const {
  return kMinWidth;
}

FX_FLOAT CPDFSDK_Annot::GetMinHeight() const {
  return kMinHeight;
}

int CPDFSDK_Annot::GetLayoutOrder() const {
  return 5;
}

CPDF_Annot* CPDFSDK_Annot::GetPDFAnnot() const {
  return nullptr;
}

CFX_ByteString CPDFSDK_Annot::GetType() const {
  return "";
}

CFX_ByteString CPDFSDK_Annot::GetSubType() const {
  return "";
}

void CPDFSDK_Annot::SetRect(const CFX_FloatRect& rect) {}

CFX_FloatRect CPDFSDK_Annot::GetRect() const {
  return CFX_FloatRect();
}

void CPDFSDK_Annot::Annot_OnDraw(CFX_RenderDevice* pDevice,
                                 CFX_Matrix* pUser2Device,
                                 CPDF_RenderOptions* pOptions) {}

FX_BOOL CPDFSDK_Annot::IsSelected() {
  return m_bSelected;
}

void CPDFSDK_Annot::SetSelected(FX_BOOL bSelected) {
  m_bSelected = bSelected;
}

UnderlyingPageType* CPDFSDK_Annot::GetUnderlyingPage() {
#ifdef PDF_ENABLE_XFA
  return GetPDFXFAPage();
#else   // PDF_ENABLE_XFA
  return GetPDFPage();
#endif  // PDF_ENABLE_XFA
}

CPDF_Page* CPDFSDK_Annot::GetPDFPage() {
  return m_pPageView ? m_pPageView->GetPDFPage() : nullptr;
}