Allow external font-path configuration from pdfium_test.
[pdfium.git] / fpdfsdk / src / pdfwindow / PWL_ListCtrl.cpp
index 603bb4a..e01ce5c 100644 (file)
-// Copyright 2014 PDFium Authors. All rights reserved.\r
-// Use of this source code is governed by a BSD-style license that can be\r
-// found in the LICENSE file.\r
\r
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
-\r
-#include "../../include/pdfwindow/PDFWindow.h"\r
-#include "../../include/pdfwindow/PWL_Wnd.h"\r
-#include "../../include/pdfwindow/PWL_ListCtrl.h"\r
-\r
-/* ---------------------------- CPWL_ListCtrl ---------------------------- */\r
-\r
-CPWL_ListCtrl::CPWL_ListCtrl() : \r
-       m_rcContent(0,0,0,0),\r
-       m_ptScroll(0,0), \r
-       m_fItemSpace(0.0f),\r
-       m_fTopSpace(0.0f),\r
-       m_fBottomSpace(0.0f)\r
-{\r
-}\r
-\r
-CPWL_ListCtrl::~CPWL_ListCtrl()\r
-{\r
-}\r
-\r
-void CPWL_ListCtrl::SetScrollPos(const CPDF_Point& point)\r
-{\r
-       m_ptScroll = point;\r
-\r
-       if (m_ptScroll.x < m_rcContent.left)\r
-               m_ptScroll.x = m_rcContent.left;\r
-\r
-       if (m_ptScroll.x > m_rcContent.right)\r
-               m_ptScroll.x = m_rcContent.right;\r
-\r
-       if (m_ptScroll.y > m_rcContent.top)\r
-               m_ptScroll.y = m_rcContent.top;\r
-\r
-       if (m_ptScroll.y < m_rcContent.bottom)\r
-               m_ptScroll.y = m_rcContent.bottom;      \r
-}\r
-\r
-CPDF_Point CPWL_ListCtrl::GetScrollPos() const\r
-{\r
-       return m_ptScroll;\r
-}\r
-\r
-CPDF_Rect CPWL_ListCtrl::GetScrollArea() const\r
-{\r
-       return m_rcContent;\r
-}\r
-\r
-void CPWL_ListCtrl::ResetFace()\r
-{\r
-       ResetAll(FALSE, 0);\r
-}\r
-\r
-void CPWL_ListCtrl::ResetContent(FX_INT32 nStart)\r
-{\r
-       if (nStart < 0)\r
-               nStart = 0;\r
-       if (nStart >= 0 && nStart < m_aChildren.GetSize())\r
-               ResetAll(TRUE, nStart);\r
-}\r
-\r
-FX_FLOAT CPWL_ListCtrl::GetContentsHeight(FX_FLOAT fLimitWidth)\r
-{\r
-       FX_FLOAT fRet = m_fTopSpace;\r
-\r
-       FX_FLOAT fBorderWidth = (FX_FLOAT)this->GetBorderWidth();\r
-\r
-       if (fLimitWidth > fBorderWidth* 2)\r
-       {\r
-               for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++)\r
-               {\r
-                       if (CPWL_Wnd* pChild = m_aChildren.GetAt(i))\r
-                       {\r
-                               FX_FLOAT fLeft = pChild->GetItemLeftMargin();\r
-                               FX_FLOAT fRight = pChild->GetItemRightMargin();\r
-\r
-                               fRet += pChild->GetItemHeight(fLimitWidth - fBorderWidth* 2 - fLeft - fRight);\r
-                               fRet += m_fItemSpace;\r
-                       }\r
-               }\r
-\r
-               fRet -= m_fItemSpace;\r
-       }\r
-\r
-       fRet += m_fBottomSpace;\r
-\r
-       return fRet;\r
-}\r
-\r
-void CPWL_ListCtrl::ResetAll(FX_BOOL bMove, FX_INT32 nStart)\r
-{\r
-       CPDF_Rect rcClient = GetClientRect();\r
-\r
-       FX_FLOAT fWidth = rcClient.Width();\r
-\r
-       FX_FLOAT fy = 0.0f - m_fTopSpace;\r
-\r
-       if (nStart-1 >= 0 && nStart-1 < m_aChildren.GetSize())\r
-               if (CPWL_Wnd* pChild = m_aChildren.GetAt(nStart-1))\r
-                       fy = pChild->GetWindowRect().bottom - m_fItemSpace;\r
-\r
-       for (FX_INT32 i=nStart,sz=m_aChildren.GetSize(); i<sz; i++)\r
-       {\r
-               if (CPWL_Wnd* pChild = m_aChildren.GetAt(i))\r
-               {\r
-                       FX_FLOAT fLeft = pChild->GetItemLeftMargin();\r
-                       FX_FLOAT fRight = pChild->GetItemRightMargin();\r
-\r
-                       pChild->SetChildMatrix(\r
-                               CPDF_Matrix(1,0,0,1, \r
-                               rcClient.left - m_ptScroll.x, \r
-                               rcClient.top - m_ptScroll.y)\r
-                               );\r
-\r
-                       if (bMove)\r
-                       {\r
-                               FX_FLOAT fItemHeight = pChild->GetItemHeight(fWidth - fLeft - fRight);\r
-                               pChild->Move(CPDF_Rect(fLeft, fy-fItemHeight, fWidth - fRight, fy), TRUE, FALSE);\r
-                               fy -= fItemHeight;\r
-                               fy -= m_fItemSpace;\r
-                       }\r
-               }\r
-       }\r
-\r
-       fy += m_fItemSpace;\r
-\r
-       fy -= m_fBottomSpace;\r
-\r
-       if (bMove)\r
-       {\r
-               m_rcContent.left = 0;\r
-               m_rcContent.top = 0;\r
-               m_rcContent.right = fWidth;\r
-               m_rcContent.bottom = fy;\r
-       }\r
-}\r
-\r
-void CPWL_ListCtrl::SetItemSpace(FX_FLOAT fSpace)\r
-{\r
-       m_fItemSpace = fSpace;\r
-}\r
-\r
-void CPWL_ListCtrl::SetTopSpace(FX_FLOAT fSpace)\r
-{\r
-       m_fTopSpace = fSpace;\r
-}\r
-\r
-void CPWL_ListCtrl::SetBottomSpace(FX_FLOAT fSpace)\r
-{\r
-       m_fBottomSpace = fSpace;\r
-}\r
-\r
-void CPWL_ListCtrl::RePosChildWnd()\r
-{\r
-       ResetFace();\r
-}\r
-\r
-void CPWL_ListCtrl::DrawChildAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)\r
-{\r
-       pDevice->SaveState();\r
-       CPDF_Rect rcClient = GetClientRect();\r
-       CPDF_Rect rcTemp = rcClient;\r
-       pUser2Device->TransformRect(rcTemp);\r
-       FX_RECT rcClip((FX_INT32)rcTemp.left,\r
-               (FX_INT32)rcTemp.bottom,\r
-               (FX_INT32)rcTemp.right,\r
-               (FX_INT32)rcTemp.top);\r
-\r
-       pDevice->SetClip_Rect(&rcClip);\r
-\r
-       for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++)\r
-       {\r
-               if (CPWL_Wnd * pChild = m_aChildren.GetAt(i))\r
-               {\r
-                       CPDF_Rect rcChild = pChild->ChildToParent(pChild->GetWindowRect());\r
-                       if (!(rcChild.top < rcClient.bottom || rcChild.bottom > rcClient.top))\r
-                       {\r
-                               CPDF_Matrix mt = pChild->GetChildMatrix();\r
-                               if (mt.IsIdentity())\r
-                               {\r
-                                       pChild->DrawAppearance(pDevice,pUser2Device);\r
-                               }\r
-                               else\r
-                               {\r
-                                       mt.Concat(*pUser2Device);\r
-                                       pChild->DrawAppearance(pDevice,&mt);\r
-                               }\r
-                       }\r
-               }\r
-       }\r
-       \r
-       pDevice->RestoreState();\r
-}\r
-\r
-FX_INT32 CPWL_ListCtrl::GetItemIndex(CPWL_Wnd* pItem)\r
-{\r
-       for (FX_INT32 i=0, sz=m_aChildren.GetSize(); i<sz; i++)\r
-       {\r
-               if (pItem == m_aChildren.GetAt(i))\r
-                       return i;\r
-       }\r
-\r
-       return -1;\r
-}\r
-\r
-CPDF_Point CPWL_ListCtrl::InToOut(const CPDF_Point& point) const\r
-{\r
-       CPDF_Rect rcClient = GetClientRect();\r
-\r
-       return CPDF_Point(point.x + rcClient.left - m_ptScroll.x, \r
-               point.y + rcClient.top - m_ptScroll.y);\r
-}\r
-\r
-CPDF_Point CPWL_ListCtrl::OutToIn(const CPDF_Point& point) const\r
-{\r
-       CPDF_Rect rcClient = GetClientRect();\r
-\r
-       return CPDF_Point(point.x - rcClient.left + m_ptScroll.x, \r
-               point.y - rcClient.top + m_ptScroll.y);\r
-}\r
-\r
-CPDF_Rect CPWL_ListCtrl::InToOut(const CPDF_Rect& rect) const\r
-{\r
-       CPDF_Rect rcClient = GetClientRect();\r
-\r
-       return CPDF_Rect(rect.left + rcClient.left - m_ptScroll.x,\r
-               rect.bottom + rcClient.top - m_ptScroll.y,\r
-               rect.right + rcClient.left - m_ptScroll.x,\r
-               rect.top + rcClient.top - m_ptScroll.y);\r
-}\r
-\r
-CPDF_Rect CPWL_ListCtrl::OutToIn(const CPDF_Rect& rect) const\r
-{\r
-       CPDF_Rect rcClient = GetClientRect();\r
-\r
-       return CPDF_Rect(rect.left - rcClient.left + m_ptScroll.x,\r
-               rect.bottom - rcClient.top + m_ptScroll.y,\r
-               rect.right - rcClient.left + m_ptScroll.x,\r
-               rect.top - rcClient.top + m_ptScroll.y);\r
-}\r
-\r
+// Copyright 2014 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 "../../include/pdfwindow/PDFWindow.h"
+#include "../../include/pdfwindow/PWL_Wnd.h"
+#include "../../include/pdfwindow/PWL_ListCtrl.h"
+
+/* ---------------------------- CPWL_ListCtrl ---------------------------- */
+
+CPWL_ListCtrl::CPWL_ListCtrl()
+    : m_rcContent(0, 0, 0, 0),
+      m_ptScroll(0, 0),
+      m_fItemSpace(0.0f),
+      m_fTopSpace(0.0f),
+      m_fBottomSpace(0.0f) {}
+
+CPWL_ListCtrl::~CPWL_ListCtrl() {}
+
+void CPWL_ListCtrl::SetScrollPos(const CPDF_Point& point) {
+  m_ptScroll = point;
+
+  if (m_ptScroll.x < m_rcContent.left)
+    m_ptScroll.x = m_rcContent.left;
+
+  if (m_ptScroll.x > m_rcContent.right)
+    m_ptScroll.x = m_rcContent.right;
+
+  if (m_ptScroll.y > m_rcContent.top)
+    m_ptScroll.y = m_rcContent.top;
+
+  if (m_ptScroll.y < m_rcContent.bottom)
+    m_ptScroll.y = m_rcContent.bottom;
+}
+
+CPDF_Point CPWL_ListCtrl::GetScrollPos() const {
+  return m_ptScroll;
+}
+
+CPDF_Rect CPWL_ListCtrl::GetScrollArea() const {
+  return m_rcContent;
+}
+
+void CPWL_ListCtrl::ResetFace() {
+  ResetAll(FALSE, 0);
+}
+
+void CPWL_ListCtrl::ResetContent(int32_t nStart) {
+  if (nStart < 0)
+    nStart = 0;
+  if (nStart >= 0 && nStart < m_aChildren.GetSize())
+    ResetAll(TRUE, nStart);
+}
+
+FX_FLOAT CPWL_ListCtrl::GetContentsHeight(FX_FLOAT fLimitWidth) {
+  FX_FLOAT fRet = m_fTopSpace;
+
+  FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
+
+  if (fLimitWidth > fBorderWidth * 2) {
+    for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
+      if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
+        FX_FLOAT fLeft = pChild->GetItemLeftMargin();
+        FX_FLOAT fRight = pChild->GetItemRightMargin();
+
+        fRet += pChild->GetItemHeight(fLimitWidth - fBorderWidth * 2 - fLeft -
+                                      fRight);
+        fRet += m_fItemSpace;
+      }
+    }
+
+    fRet -= m_fItemSpace;
+  }
+
+  fRet += m_fBottomSpace;
+
+  return fRet;
+}
+
+void CPWL_ListCtrl::ResetAll(FX_BOOL bMove, int32_t nStart) {
+  CPDF_Rect rcClient = GetClientRect();
+
+  FX_FLOAT fWidth = rcClient.Width();
+
+  FX_FLOAT fy = 0.0f - m_fTopSpace;
+
+  if (nStart - 1 >= 0 && nStart - 1 < m_aChildren.GetSize())
+    if (CPWL_Wnd* pChild = m_aChildren.GetAt(nStart - 1))
+      fy = pChild->GetWindowRect().bottom - m_fItemSpace;
+
+  for (int32_t i = nStart, sz = m_aChildren.GetSize(); i < sz; i++) {
+    if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
+      FX_FLOAT fLeft = pChild->GetItemLeftMargin();
+      FX_FLOAT fRight = pChild->GetItemRightMargin();
+
+      pChild->SetChildMatrix(CPDF_Matrix(1, 0, 0, 1,
+                                         rcClient.left - m_ptScroll.x,
+                                         rcClient.top - m_ptScroll.y));
+
+      if (bMove) {
+        FX_FLOAT fItemHeight = pChild->GetItemHeight(fWidth - fLeft - fRight);
+        pChild->Move(CPDF_Rect(fLeft, fy - fItemHeight, fWidth - fRight, fy),
+                     TRUE, FALSE);
+        fy -= fItemHeight;
+        fy -= m_fItemSpace;
+      }
+    }
+  }
+
+  fy += m_fItemSpace;
+
+  fy -= m_fBottomSpace;
+
+  if (bMove) {
+    m_rcContent.left = 0;
+    m_rcContent.top = 0;
+    m_rcContent.right = fWidth;
+    m_rcContent.bottom = fy;
+  }
+}
+
+void CPWL_ListCtrl::SetItemSpace(FX_FLOAT fSpace) {
+  m_fItemSpace = fSpace;
+}
+
+void CPWL_ListCtrl::SetTopSpace(FX_FLOAT fSpace) {
+  m_fTopSpace = fSpace;
+}
+
+void CPWL_ListCtrl::SetBottomSpace(FX_FLOAT fSpace) {
+  m_fBottomSpace = fSpace;
+}
+
+void CPWL_ListCtrl::RePosChildWnd() {
+  ResetFace();
+}
+
+void CPWL_ListCtrl::DrawChildAppearance(CFX_RenderDevice* pDevice,
+                                        CPDF_Matrix* pUser2Device) {
+  pDevice->SaveState();
+  CPDF_Rect rcClient = GetClientRect();
+  CPDF_Rect rcTemp = rcClient;
+  pUser2Device->TransformRect(rcTemp);
+  FX_RECT rcClip((int32_t)rcTemp.left, (int32_t)rcTemp.bottom,
+                 (int32_t)rcTemp.right, (int32_t)rcTemp.top);
+
+  pDevice->SetClip_Rect(&rcClip);
+
+  for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
+    if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) {
+      CPDF_Rect rcChild = pChild->ChildToParent(pChild->GetWindowRect());
+      if (!(rcChild.top < rcClient.bottom || rcChild.bottom > rcClient.top)) {
+        CPDF_Matrix mt = pChild->GetChildMatrix();
+        if (mt.IsIdentity()) {
+          pChild->DrawAppearance(pDevice, pUser2Device);
+        } else {
+          mt.Concat(*pUser2Device);
+          pChild->DrawAppearance(pDevice, &mt);
+        }
+      }
+    }
+  }
+
+  pDevice->RestoreState();
+}
+
+int32_t CPWL_ListCtrl::GetItemIndex(CPWL_Wnd* pItem) {
+  for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) {
+    if (pItem == m_aChildren.GetAt(i))
+      return i;
+  }
+
+  return -1;
+}
+
+CPDF_Point CPWL_ListCtrl::InToOut(const CPDF_Point& point) const {
+  CPDF_Rect rcClient = GetClientRect();
+
+  return CPDF_Point(point.x + rcClient.left - m_ptScroll.x,
+                    point.y + rcClient.top - m_ptScroll.y);
+}
+
+CPDF_Point CPWL_ListCtrl::OutToIn(const CPDF_Point& point) const {
+  CPDF_Rect rcClient = GetClientRect();
+
+  return CPDF_Point(point.x - rcClient.left + m_ptScroll.x,
+                    point.y - rcClient.top + m_ptScroll.y);
+}
+
+CPDF_Rect CPWL_ListCtrl::InToOut(const CPDF_Rect& rect) const {
+  CPDF_Rect rcClient = GetClientRect();
+
+  return CPDF_Rect(rect.left + rcClient.left - m_ptScroll.x,
+                   rect.bottom + rcClient.top - m_ptScroll.y,
+                   rect.right + rcClient.left - m_ptScroll.x,
+                   rect.top + rcClient.top - m_ptScroll.y);
+}
+
+CPDF_Rect CPWL_ListCtrl::OutToIn(const CPDF_Rect& rect) const {
+  CPDF_Rect rcClient = GetClientRect();
+
+  return CPDF_Rect(rect.left - rcClient.left + m_ptScroll.x,
+                   rect.bottom - rcClient.top + m_ptScroll.y,
+                   rect.right - rcClient.left + m_ptScroll.x,
+                   rect.top - rcClient.top + m_ptScroll.y);
+}